mirror of
https://github.com/garrytan/gstack.git
synced 2026-10-31 22:14:25 +01:00
* docs(designs): gstack field wave plan (2026-10-12) and the shared simulated Capy host fixture
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix(autoplan): scope keys on rendered surfaces, per-axis provenance, --no-dx and a read-only plan marker
UI scope reads the Implementation plan only and needs a rendered file path or a UI
term next to a visual noun; bare UI words stay weak evidence (sections load, no
Design phase). Scope records sources {ui,dx} (flag|marker|detected), --no-dx turns
DX off, a first-line <!-- gstack-autoplan-scope: ... --> marker is read and never
written, and the first next prints SCOPE: evidence plus a SCOPE_PIN hint. The
snapshot tool's scope output carries uiRequired from the same detector and
autoplan Step 2 uses it instead of a prose grep (field wave item 11).
Intentional pin change: test/review-checklists.test.ts Scope literal and the
source= line shape (source=ui:detected,dx:detected).
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix(plan-reality): a receipt per measured number, the rule text for a rule claim, dot-path receipts
Each clause stating a measured quantity (a unit, or a number after measured/costs/
takes/took) needs its own receipt; misses print unreceipted_numbers=<n> and one
NUMBER_UNRECEIPTED: <clause> line each. A line claiming a decision rule must quote
it or link its file:line (unquoted=<n>). Either miss maps to the existing verdict
(incomplete unattended, repair otherwise). RECEIPT_RE accepts dot paths and needs
a hex letter or a commit/backtick context for a sha. New pure checkPlanReality(planText)
runs the same checks over plan prose for gstack-autoplan submit (field wave item 12).
The unreceipted= text token is now pinned as well as the JSON.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(autoplan): generated DRIVER.md, the compact entry for a parent driving gstack-autoplan
autoplan/DRIVER.md (from autoplan/DRIVER.md.tmpl) is what a parent agent on any host
reads instead of autoplan/SKILL.md: phase order and scope flags, the next/submit/
answer/revise/export loop with the plan-specified submit --record/--attest/
--unavailable, revise --incorporates/--withdraw and next --scaffold, the reviewer
RESULT FORMAT, the gate grammar including all as-is, the run files, the result codes
and the coordinator contract, every list rendered from code (117 lines). gen:skill-docs
emits it as a Claude asset, so normal, out-dir and dry-run inventories and the
freshness check cover it. gstack-autoplan --help and the first next print
DRIVER: <root>/autoplan/DRIVER.md, resolved through an install root's recorded
.source-path (new lib/source-root.ts) (field wave item 13).
Intentional pin change: test/gen-skill-docs-checks.test.ts asset inventory gains
autoplan/DRIVER.md.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(doctor): --min-revision, a launch Bun found off PATH, planning-only pins SKIP
gstack-doctor --check gains --min-revision <v>|unknown: below it the revision
row FAILs with REVISION_BELOW_MINIMUM naming the Capy wrapper or
bin/gstack-upgrade; unknown says so and never claims the minimum. The runtime
and pins rows name a supported Bun found in $BUN_INSTALL/bin (not on PATH)
with the export/GSTACK_LAUNCH fix (gstack_bun_launch_dir, one helper in
bin/gstack-bun-version.sh). --for a planning-only workflow (autoplan, the plan
reviews, office-hours) reports a repo test-pin mismatch as SKIP pins
(planning-only; ...). New result codes UPGRADE_REFUSED, UPGRADE_FETCH_FAILED,
REVISION_BELOW_MINIMUM, CAPY_WRAPPER_STALE, INSTALL_UNVERIFIED with
troubleshooting anchors; REVISION_UNMET's fix names bin/gstack-upgrade.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(install): install verdict and install admission at skill start
bin/gstack-install-verdict.sh (Bash) and lib/install-verdict.ts (TypeScript)
are the one reader of the install verdict gstack-capy-install writes to
<state root>/install-verdicts/<sha256(checkout realpath)>.json (checkout,
HEAD, workflow and required components, planning-only pins, trailer). The
source checkout and capy/support.env resolve through gstack_source_root /
sourceRoot, which follow an installed root's .source-path.
gstack-skill-start, after SESSION_KIND: an unattended session (any host)
refuses on a PATH Bun below the supported minimum; with GSTACK_CAPY=1 an
unattended or explicit spawned session also refuses without a passing
verdict for this checkout, HEAD and workflow (INSTALL_UNVERIFIED). A refusal
prints the INSTALL: row, an install-refused instruction block bound to its
SESSION_ID, GSTACK_RESULT ... status=refused run=- and exits 3. Ambient
spawned sessions warn; GSTACK_ALLOW_UNSUPPORTED_RUNTIME=1 admits and says so.
capy/support.env declares GSTACK_MIN_REVISION and GSTACK_CAPY_MIN_WRAPPER.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(capy-install): launch PATH, Bun reuse and CI pins, setup skip on HEAD, verdict, --check
The GSTACK_LAUNCH line carries PATH=<dir>:$PATH when the certified Bun is not
first on PATH, plus GSTACK_CAPY=1 and GSTACK_INSTALL_VERDICT, and
GSTACK_LAUNCH_PATH: <dir>; the doctor runs with that PATH. A supported Bun in
$BUN_INSTALL/bin is reused instead of downloaded again. Project pins are read
with bin/gstack-runtime-pins.ts (CI lanes included): when every exact pin is
gstack's verified version the archive is installed alongside a different PATH
Bun; any other exact pin is RUNTIME_PIN_CONFLICT. Both ./setup runs are
skipped when this HEAD was set up with the same hosts, model and browser flag
and the check passes (never after a fast-forward); a failed setup ends with
gstack: fail setup and is retried next run. --check certifies only;
GSTACK_CAPY_LOCK_HELD=1 accepts the bootstrapper's held lock; result anchors
come from the generated components table; REV_NOTE names bin/gstack-upgrade.
Intentional pin change: test/gstack-capy-install.test.ts --revision trailer
now names <root>/bin/gstack-upgrade (the old text named a command that never
existed).
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* result codes: PLAN_SECTIONS_INVALID, PLAN_AMEND_PENDING, GSTACK_VERSION_CHANGED, INSTALL_VERDICT_FAILED, ARTIFACT_GATE_UNSETTLED
Troubleshooting anchors for each and the regenerated doctor components table (field wave lane B-core).
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* artifact contract: changes, recommended_basis, carried decisions, attested count, settled-gate check
Findings and decisions carry the user challenge's `changes` value; decisions record recommended_basis, origin,
carried_from and chosen_text; validate refuses a complete run with an unsettled gate (ARTIFACT_GATE_UNSETTLED) and
prints attested=<n>. The gate reply grammar gains `all as-is` and resolves partial replies against prior answers
(field wave B2a/B2b).
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* autoplan: run-state fields, plan-text hashing, version migration and admission modules
RunState gains gstack_version, plan_input/heading, scope_flags, plan_revision, amendments and plan_reality; voices
record receipt kind and reviewed hash. New pure modules: Implementation-plan review hash, scaffold and drift lines
(B1c); gstack_version stamp and legacy decision-id migration (B1a); install-verdict and Bun-minimum admission
with a local verdict shim until lane A's lib/install-verdict.ts lands.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
bin/gstack-autoplan-snapshot.ts exports its section scanner and review projection, and initializes only a plan with
no section headings by wrapping it.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* autoplan: closable runs - submit --record/--attest/--unavailable, revise, amendment interlock, agreeing-UC defaults, admission
B1a: an older run directory prints GSTACK_VERSION_CHANGED once and migrates legacy decision ids; a newer one refuses.
B1b: submit binds hand-run records (fence, table, severity list, No findings.), attested binds need --attempt,
--attempt is optional with one open attempt, --unavailable/--failed close an outside voice native_only, and submit
caches the plan-reality report by Implementation-plan hash.
B1c: revise reviews a revised plan in the same run as one recoverable transaction (reopen on hash drift plus Eng,
add newly in-scope phases, .r<rev>/.v<k> archives, gate_rev+1 at the gate); PLAN_SECTIONS_INVALID and next --scaffold;
PLAN_CHANGED / PLAN_SOURCE_CHANGED drift hints.
B2a/B2b: user challenges carry changes; agreeing voices with the same changes on a confirmed finding recommend b with
both remedies shown (or the reconcile proposal); accepted changes print APPLY and become pending amendments that next
and export refuse past until revise --incorporates names them or --withdraw drops one; all as-is; partial replies,
DECIDED block, carry-forward and rerun demotion.
Mutating verbs pass admission (GSTACK_CAPY install verdict; unattended Bun minimum; override recorded as a deviation).
Intentional pin rewrite: test/autoplan-answer-invalidation.test.ts reopen tests now revise --incorporates before rerun.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(upgrade): bin/gstack-upgrade, the unattended fast-forward every fix line names
--check fetches and prints current|behind <installed> -> <remote> (<n>
commits); the default fast-forwards to the remote default branch tip and
reinstalls (bin/gstack-capy-install on a Capy install, else ./setup
--refresh-registered), completing a pending reinstall on the next run. It
refuses (UPGRADE_REFUSED, exit 3, nothing changed) a dirty tracked byte, a
diverged commit, a pinned checkout, the incoming Bun floor and a held
.setup-lock; never stashes or resets; an unreachable remote is
UPGRADE_FETCH_FAILED. Fetches are receipted (fail-open). The unattended
skill-end UPGRADE_AVAILABLE line is followed by UPGRADE_COMMAND naming it.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(capy): vendored Capy skill, frozen bootstrapper and full wrapper bin/gstack-capy-session
capy/skill/gstack/ is the Drive skill's source of truth. scripts/install.sh
is a frozen bootstrapper: it prints gstack-capy-skill: wrapper <n> (<path>),
clones or fetches under .gstack-capy-install.lock, reads the remote
capy/support.env (FETCH_HEAD), fast-forwards a clean unpinned checkout below
GSTACK_MIN_REVISION (refusing dirty, diverged or pinned checkouts with the
exact commands; GSTACK_CAPY_AUTO_UPGRADE=0 disables), and execs the
checkout's own bin/gstack-capy-session with GSTACK_CAPY_LOCK_HELD=1 so the
held lock is never taken twice. Offline it says the remote minimum is
unknown. A Drive copy older than GSTACK_CAPY_MIN_WRAPPER prints an owner
action (CAPY_WRAPPER_STALE). SKILL.md: check at session start, install
lazily before the first workflow, the GSTACK_LAUNCH line, the trailer rule,
the subagent first-report line, gstack-pregate sealed before any push, and
the autoplan/DRIVER.md pointer. The context-budget fixture gains the skill's
entry.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* docs: Capy install layers, lazy install, snapshot bake, forward-only recovery, raising the minimum
docs/capy-install.md describes the three layers (Drive bootstrapper, full
wrapper, installer), the lazy install, the GSTACK_LAUNCH line, install
admission, baking gstack into a Capy snapshot, and that recovery after an
interrupted fast-forward completes or refuses the pending install stages
(checking out an older commit is not a rollback). docs/CHANGELOG_STYLE.md
(the release doc; there is no docs/RELEASING.md) says when
GSTACK_MIN_REVISION may be raised.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* refactor(capy): the stale-copy owner action moves from the frozen bootstrapper to bin/gstack-capy-session
The checkout-owned full wrapper reads GSTACK_CAPY_MIN_WRAPPER through
gstack_support_env_get(gstack_source_root) and compares it with the
bootstrapper revision it was handed, so the rule can change without
recopying the Drive skill. The bootstrapper keeps only what a stale checkout
cannot do: clone, fetch, read the remote minimum, fast-forward, exec.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* v1.91.96.0: honest install and self-upgrade on Capy; supported minimum 1.91.96.0
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* v1.91.97.0: closable unattended autoplan runs on Capy
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* test: drop the helper-only Capy host fixture test (test-of-test ratchet); lane tests exercise the helper
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix(autoplan): revise naming a non-pending decision refuses with AMENDMENT_UNKNOWN, not PLAN_AMEND_PENDING
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* test: bound the new sync spawns in the install-verdict and wrapper tests (spawnSync tripwire)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* test(autoplan): pin CLI refusals to the result-code registry's fix text
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix(gen-skill-docs): emit autoplan/DRIVER.md only when the autoplan template is in the tree (setup fixtures with a skill subset)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix(autoplan): run.lock is linked into place with its owner written; a fresh unreadable lock is held, not stolen
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* ci(paid-pr-profile): the vendored Capy skill is free-only; free-only files are not prompts needing paid coverage
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* chore(harness): non-behavioral HARNESS_VERSION decision for the PR-profile free-only rule
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* test(doctor): lane A runtime and pins cases are platform-neutral (bash paths; a lane-free .bun-version pin)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* docs(designs): field wave plan with amendments and the gate rev 2-3 review record (ARTIFACT_VALID, 3 gate revisions)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix(capy-install): follow a project's exact Bun pin above the minimum when gstack has its verified archive (adds Bun 1.4.3)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* docs: the installer follows a verified exact project Bun pin (capy-install, troubleshooting, changelog)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix(capy-install): the install reason names the project's pin and gstack's real minimum
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* ci: run the main-targeted checks after retargeting #3165 to main
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* test(autoplan-admission): the PATH-Bun refusal case needs the POSIX Capy host stub; skip it on Windows
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
---------
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
363 lines
19 KiB
TypeScript
363 lines
19 KiB
TypeScript
import { afterAll, beforeAll, describe, expect, spyOn, test } from 'bun:test';
|
|
import * as fs from 'fs';
|
|
import * as os from 'os';
|
|
import * as path from 'path';
|
|
import { createHash } from 'crypto';
|
|
import { spawnSync } from 'child_process';
|
|
import { runGeneration, type GeneratedArtifact, type GenerationResult } from '../scripts/gen-skill-docs';
|
|
import { includesSkill } from '../scripts/discover-skills';
|
|
import { getHostConfig, ALL_HOST_NAMES } from '../hosts/index';
|
|
import { checkGeneratedFreshness, validateGeneratedArtifact } from '../scripts/skill-check';
|
|
|
|
const ROOT = path.resolve(import.meta.dir, '..');
|
|
const base = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-check-contract-'));
|
|
const render = path.join(base, 'render');
|
|
let generated: GenerationResult;
|
|
|
|
/** Hashes AND mtimes catch rewriting identical files; directory entries catch
|
|
* mkdir-only side effects. Do not follow symlinks back into the checkout. */
|
|
function inventory(root: string): unknown[] {
|
|
if (!fs.existsSync(root)) return [];
|
|
return fs.readdirSync(root).sort().flatMap(name => {
|
|
const file = path.join(root, name);
|
|
const stat = fs.lstatSync(file);
|
|
return [[file, stat.mtimeMs, stat.isDirectory() ? 'directory'
|
|
: stat.isSymbolicLink() ? fs.readlinkSync(file)
|
|
: createHash('sha256').update(fs.readFileSync(file)).digest('hex')],
|
|
...(stat.isDirectory() ? inventory(file) : [])];
|
|
});
|
|
}
|
|
|
|
beforeAll(async () => {
|
|
generated = await runGeneration({ host: 'all', outputRoot: render, contentLinkRoot: null });
|
|
expect(generated.exitCode, JSON.stringify(generated.diagnostics)).toBe(0);
|
|
}, 120_000);
|
|
afterAll(() => fs.rmSync(base, { recursive: true, force: true }));
|
|
|
|
describe('generator artifact and dry-run contract', () => {
|
|
test('all host artifacts validate, with canonical links and host exclusions', () => {
|
|
expect([...new Set(generated.artifacts.filter(a => a.host).map(a => a.host))].sort()).toEqual([...ALL_HOST_NAMES].sort());
|
|
expect([...new Set(generated.artifacts.map(a => a.kind))].sort()).toEqual(['asset', 'digest', 'doctor-components', 'index', 'metadata', 'openclaw', 'section', 'skill']);
|
|
expect(generated.artifacts.some(a => a.relativePath === 'claude-code/SKILL.md')).toBe(false);
|
|
expect(generated.artifacts.some(a => a.relativePath === '.agents/skills/gstack-claude-code/SKILL.md')).toBe(true);
|
|
expect(generated.artifacts.some(a => a.relativePath === '.agents/skills/gstack-codex/SKILL.md')).toBe(false);
|
|
expect(fs.readFileSync(path.join(render, 'ship/SKILL.md'), 'utf-8')).toContain('~/.claude/skills/gstack/ship/sections/');
|
|
expect(generated.artifacts.flatMap(a => validateGeneratedArtifact(render, a))).toEqual([]);
|
|
expect(generated.artifacts.filter(a => a.kind === 'asset').sort((a, b) => a.relativePath.localeCompare(b.relativePath))).toEqual([
|
|
{ relativePath: 'review/design-checklist.md', kind: 'asset', host: 'claude' },
|
|
{ relativePath: 'lib/dom-dump.js', kind: 'asset', host: 'claude' },
|
|
{ relativePath: 'autoplan/DRIVER.md', kind: 'asset', host: 'claude' },
|
|
...ALL_HOST_NAMES.filter(host => includesSkill(getHostConfig(host), 'qa')).map(host => ({
|
|
relativePath: host === 'claude' ? 'qa/templates/functional-report-template.md'
|
|
: `${getHostConfig(host).hostSubdir}/skills/gstack-qa/templates/functional-report-template.md`,
|
|
kind: 'asset', host,
|
|
})),
|
|
].sort((a, b) => a.relativePath.localeCompare(b.relativePath)));
|
|
});
|
|
|
|
test('include-minus-skip semantics share one predicate', () => {
|
|
const host = getHostConfig('claude');
|
|
expect(includesSkill(host, 'claude-code')).toBe(false);
|
|
expect(includesSkill(host, '.')).toBe(true);
|
|
const filtered = { ...host, generation: { ...host.generation, includeSkills: ['ship', 'claude-code'] } };
|
|
expect(includesSkill(filtered, 'ship')).toBe(true);
|
|
expect(includesSkill(filtered, 'claude-code')).toBe(false);
|
|
expect(includesSkill(filtered, 'review')).toBe(false);
|
|
});
|
|
|
|
test('fresh all-host dry run does not change bytes, mtimes, or directories', async () => {
|
|
const before = inventory(render);
|
|
const result = await runGeneration({ host: 'all', outputRoot: render, dryRun: true });
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.artifacts).toEqual(generated.artifacts);
|
|
expect(inventory(render)).toEqual(before);
|
|
});
|
|
|
|
test('missing nested output root reports every artifact family without creating anything', async () => {
|
|
const parent = fs.mkdtempSync(path.join(base, 'missing-'));
|
|
const outputRoot = path.join(parent, 'not-created', 'nested');
|
|
const before = inventory(parent);
|
|
const result = await runGeneration({ host: 'all', outputRoot, dryRun: true });
|
|
expect(result.exitCode).toBe(1);
|
|
expect(result.diagnostics.filter(d => d.kind === 'stale')).toHaveLength(generated.artifacts.length);
|
|
expect(result.diagnostics.filter(d => d.kind === 'error')).toEqual([]);
|
|
expect(inventory(parent)).toEqual(before);
|
|
expect(fs.existsSync(outputRoot)).toBe(false);
|
|
});
|
|
|
|
for (const relativePath of [
|
|
'ship/SKILL.md', 'ship/sections/adversarial.md',
|
|
'.agents/skills/gstack-ship/agents/openai.yaml',
|
|
'openclaw/gstack-lite-CLAUDE.md', 'openclaw/gstack-full-CLAUDE.md', 'openclaw/gstack-plan-CLAUDE.md',
|
|
'gstack/llms.txt', 'agents-digest/gstack-AGENTS.md',
|
|
'review/design-checklist.md', 'lib/dom-dump.js',
|
|
]) {
|
|
test(`changed ${relativePath} is stale and never repaired by dry-run`, async () => {
|
|
const file = path.join(render, relativePath);
|
|
const original = fs.readFileSync(file);
|
|
try {
|
|
fs.writeFileSync(file, 'deliberately stale\n');
|
|
const before = inventory(render);
|
|
const result = await runGeneration({ host: 'all', outputRoot: render, dryRun: true });
|
|
expect(result.exitCode).toBe(1);
|
|
expect(result.diagnostics.filter(d => d.kind === 'stale').map(d => d.relativePath)).toEqual([relativePath]);
|
|
expect(inventory(render)).toEqual(before);
|
|
} finally {
|
|
fs.writeFileSync(file, original);
|
|
}
|
|
});
|
|
}
|
|
|
|
test('missing metadata directory is reported and remains absent', async () => {
|
|
const dir = path.join(render, '.agents/skills/gstack-ship/agents');
|
|
const file = path.join(dir, 'openai.yaml');
|
|
const original = fs.readFileSync(file);
|
|
try {
|
|
fs.rmSync(dir, { recursive: true });
|
|
const result = await runGeneration({ host: 'codex', outputRoot: render, dryRun: true });
|
|
expect(result.exitCode).toBe(1);
|
|
expect(result.diagnostics.some(d => d.kind === 'stale' && d.relativePath === '.agents/skills/gstack-ship/agents/openai.yaml')).toBe(true);
|
|
expect(fs.existsSync(dir)).toBe(false);
|
|
} finally {
|
|
fs.mkdirSync(dir);
|
|
fs.writeFileSync(file, original);
|
|
}
|
|
});
|
|
|
|
test('single-host filesystem errors reach the CLI exit code with actionable diagnostics', () => {
|
|
const outputRoot = fs.mkdtempSync(path.join(base, 'not-dir-'));
|
|
fs.writeFileSync(path.join(outputRoot, '.agents'), 'not a directory');
|
|
const before = inventory(outputRoot);
|
|
const result = spawnSync('bun', ['run', 'scripts/gen-skill-docs.ts', '--host', 'codex', '--dry-run', '--out-dir', outputRoot], { cwd: ROOT, encoding: 'utf-8', timeout: 120_000 });
|
|
expect(result.status).toBe(1);
|
|
expect(result.stderr).toContain('ERROR (codex)');
|
|
expect(result.stderr).toContain('ENOTDIR');
|
|
expect(inventory(outputRoot)).toEqual(before);
|
|
});
|
|
|
|
test('Windows ENOENT for a file ancestor remains an error instead of stale output', async () => {
|
|
const outputRoot = fs.mkdtempSync(path.join(base, 'windows-not-dir-'));
|
|
fs.writeFileSync(path.join(outputRoot, '.agents'), 'not a directory');
|
|
const before = inventory(outputRoot), original = fs.readFileSync;
|
|
const mock = spyOn(fs, 'readFileSync').mockImplementation(((file: fs.PathOrFileDescriptor, ...args: any[]) => {
|
|
if (String(file).startsWith(path.join(outputRoot, '.agents') + path.sep)) {
|
|
throw Object.assign(new Error('Windows: child cannot be found'), { code: 'ENOENT' });
|
|
}
|
|
return (original as any)(file, ...args);
|
|
}) as typeof fs.readFileSync);
|
|
let result: GenerationResult;
|
|
try { result = await runGeneration({ host: 'codex', dryRun: true, outputRoot }); }
|
|
finally { mock.mockRestore(); }
|
|
expect(result!.exitCode).toBe(1);
|
|
expect(result!.diagnostics).toContainEqual(expect.objectContaining({ kind: 'error', host: 'codex', message: expect.stringContaining('ENOTDIR') }));
|
|
expect(inventory(outputRoot)).toEqual(before);
|
|
});
|
|
|
|
test('all-host generation reports a partial failure and still renders subsequent hosts', async () => {
|
|
const outputRoot = fs.mkdtempSync(path.join(base, 'partial-host-error-'));
|
|
fs.writeFileSync(path.join(outputRoot, '.agents'), 'blocks only the Codex output tree');
|
|
const result = await runGeneration({ host: 'all', outputRoot });
|
|
expect(result.exitCode).toBe(1);
|
|
expect(result.diagnostics.filter(d => d.kind === 'error').map(d => d.host)).toEqual(['codex']);
|
|
for (const relativePath of [
|
|
'ship/SKILL.md', '.factory/skills/gstack-ship/SKILL.md', '.gbrain/skills/gstack-ship/SKILL.md',
|
|
'openclaw/gstack-plan-CLAUDE.md', 'gstack/llms.txt', 'agents-digest/gstack-AGENTS.md',
|
|
]) {
|
|
expect(result.artifacts.some(a => a.relativePath === relativePath)).toBe(true);
|
|
expect(fs.readFileSync(path.join(outputRoot, relativePath)).length).toBeGreaterThan(0);
|
|
}
|
|
expect(fs.readFileSync(path.join(outputRoot, '.agents'), 'utf-8')).toBe('blocks only the Codex output tree');
|
|
});
|
|
|
|
for (const relativePath of ['gstack/llms.txt', 'agents-digest/gstack-AGENTS.md', 'review/design-checklist.md', 'lib/dom-dump.js']) {
|
|
for (const dryRun of [true, false]) {
|
|
test(`shared artifact failure is awaited: ${relativePath}, dryRun=${dryRun}`, async () => {
|
|
const outputRoot = fs.mkdtempSync(path.join(base, 'shared-error-'));
|
|
fs.mkdirSync(path.join(outputRoot, relativePath), { recursive: true });
|
|
const result = await runGeneration({ host: 'claude', outputRoot, dryRun });
|
|
expect(result.exitCode).toBe(1);
|
|
expect(result.diagnostics.some(d => d.kind === 'error' && d.relativePath === relativePath)).toBe(true);
|
|
});
|
|
}
|
|
}
|
|
|
|
test.skipIf(process.platform === 'win32')('repo-root sidecar symlink skips skill and metadata without touching source', async () => {
|
|
const outputRoot = fs.mkdtempSync(path.join(base, 'sidecar-'));
|
|
const skills = path.join(outputRoot, '.agents/skills');
|
|
fs.mkdirSync(skills, { recursive: true });
|
|
fs.symlinkSync(ROOT, path.join(skills, 'gstack'), 'dir');
|
|
const source = path.join(ROOT, 'SKILL.md');
|
|
const before = fs.statSync(source).mtimeMs;
|
|
const result = await runGeneration({ host: 'codex', outputRoot });
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.diagnostics.some(d => d.kind === 'skipped' && d.relativePath === '.agents/skills/gstack/SKILL.md')).toBe(true);
|
|
expect(result.artifacts.some(a => a.relativePath.startsWith('.agents/skills/gstack/'))).toBe(false);
|
|
expect(fs.statSync(source).mtimeMs).toBe(before);
|
|
});
|
|
|
|
test('explicit content link root preserves literal dollar signs', async () => {
|
|
const outputRoot = path.join(base, 'link-render');
|
|
const contentLinkRoot = path.join(base, 'live$&');
|
|
expect((await runGeneration({ host: 'claude', outputRoot, contentLinkRoot })).exitCode).toBe(0);
|
|
const content = fs.readFileSync(path.join(outputRoot, 'ship/SKILL.md'), 'utf-8');
|
|
expect(content).toContain(`${contentLinkRoot}/ship/sections/`);
|
|
expect(content).not.toContain(`${outputRoot}/ship/sections/`);
|
|
});
|
|
});
|
|
|
|
describe('repository freshness without installed caches', () => {
|
|
const repo = path.join(base, 'fixture-repo');
|
|
function git(...args: string[]) {
|
|
const result = spawnSync('git', args, { cwd: repo, encoding: 'utf-8', timeout: 30_000 });
|
|
expect(result.status, result.stderr).toBe(0);
|
|
}
|
|
beforeAll(() => {
|
|
fs.mkdirSync(repo);
|
|
fs.copyFileSync(path.join(ROOT, '.gitignore'), path.join(repo, '.gitignore'));
|
|
for (const artifact of generated.artifacts.filter(a => !a.relativePath.startsWith('.'))) {
|
|
const file = path.join(repo, artifact.relativePath);
|
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
fs.copyFileSync(path.join(render, artifact.relativePath), file);
|
|
}
|
|
git('init', '--quiet');
|
|
git('add', '--all');
|
|
});
|
|
|
|
test('clean checkout passes without external host caches', () => {
|
|
expect(fs.existsSync(path.join(repo, '.agents'))).toBe(false);
|
|
const result = checkGeneratedFreshness(repo, render, generated.artifacts);
|
|
expect(result.diagnostics).toEqual([]);
|
|
expect(result.checked).toBe(generated.artifacts.filter(a => !a.relativePath.startsWith('.')).length);
|
|
});
|
|
|
|
test('ignored stale caches and unrelated dirty files do not affect freshness', () => {
|
|
fs.mkdirSync(path.join(repo, '.agents/skills/gstack-ship'), { recursive: true });
|
|
fs.writeFileSync(path.join(repo, '.agents/skills/gstack-ship/SKILL.md'), 'stale cache');
|
|
fs.writeFileSync(path.join(repo, 'unrelated-notes.txt'), 'unrelated work');
|
|
const before = inventory(repo);
|
|
expect(checkGeneratedFreshness(repo, render, generated.artifacts).diagnostics).toEqual([]);
|
|
expect(inventory(repo)).toEqual(before);
|
|
});
|
|
|
|
test.skipIf(process.platform === 'win32')('ignored symlink cache leaves foreign files and freshness unchanged', () => {
|
|
const foreign = fs.mkdtempSync(path.join(base, 'foreign-cache-'));
|
|
const foreignSkill = path.join(foreign, 'skills/gstack-ship/SKILL.md');
|
|
fs.mkdirSync(path.dirname(foreignSkill), { recursive: true });
|
|
fs.writeFileSync(foreignSkill, 'foreign sentinel: must never be rewritten');
|
|
const link = path.join(repo, '.factory');
|
|
fs.symlinkSync(foreign, link, 'dir');
|
|
try {
|
|
const beforeForeign = inventory(foreign);
|
|
const beforeRepo = inventory(repo);
|
|
expect(checkGeneratedFreshness(repo, render, generated.artifacts).diagnostics).toEqual([]);
|
|
expect(inventory(foreign)).toEqual(beforeForeign);
|
|
expect(inventory(repo)).toEqual(beforeRepo);
|
|
expect(fs.readlinkSync(link)).toBe(foreign);
|
|
} finally {
|
|
fs.unlinkSync(link);
|
|
}
|
|
});
|
|
|
|
test('scratch ignore evaluation preserves nested ignore rules and exceptions', () => {
|
|
const dir = path.join(repo, 'local-generated');
|
|
fs.mkdirSync(dir);
|
|
fs.writeFileSync(path.join(dir, '.gitignore'), '*.md\n!required.md\n');
|
|
const extra: GeneratedArtifact[] = [
|
|
{ relativePath: 'local-generated/ignored.md', kind: 'index' },
|
|
{ relativePath: 'local-generated/required.md', kind: 'index' },
|
|
];
|
|
const result = checkGeneratedFreshness(repo, render, [...generated.artifacts, ...extra]);
|
|
expect(result.diagnostics.map(d => [d.kind, d.relativePath])).toEqual([
|
|
['untracked', 'local-generated/required.md'],
|
|
]);
|
|
});
|
|
|
|
test('scratch ignore evaluation preserves configured excludes with a relative path', () => {
|
|
const excludes = path.join(repo, '.git', 'task-excludes');
|
|
fs.writeFileSync(excludes, 'global-generated/\n');
|
|
git('config', '--local', 'core.excludesFile', '.git/task-excludes');
|
|
try {
|
|
git('check-ignore', 'global-generated/SKILL.md');
|
|
const extra: GeneratedArtifact = { relativePath: 'global-generated/SKILL.md', kind: 'skill', host: 'claude' };
|
|
expect(checkGeneratedFreshness(repo, render, [...generated.artifacts, extra]).diagnostics).toEqual([]);
|
|
} finally {
|
|
git('config', '--local', '--unset', 'core.excludesFile');
|
|
}
|
|
});
|
|
|
|
test('missing tracked output fails without being recreated', () => {
|
|
const file = path.join(repo, 'ship/SKILL.md');
|
|
const original = fs.readFileSync(file);
|
|
try {
|
|
fs.unlinkSync(file);
|
|
expect(checkGeneratedFreshness(repo, render, generated.artifacts).diagnostics).toContainEqual({ kind: 'stale', relativePath: 'ship/SKILL.md', message: 'generated or tracked output is missing' });
|
|
expect(fs.existsSync(file)).toBe(false);
|
|
} finally { fs.writeFileSync(file, original); }
|
|
});
|
|
|
|
test('new nonignored output must be tracked even when bytes match', () => {
|
|
git('update-index', '--force-remove', '--', 'ship/SKILL.md');
|
|
try {
|
|
expect(checkGeneratedFreshness(repo, render, generated.artifacts).diagnostics.some(d => d.kind === 'untracked' && d.relativePath === 'ship/SKILL.md')).toBe(true);
|
|
} finally { git('add', '--', 'ship/SKILL.md'); }
|
|
});
|
|
|
|
test('tracked ignored output is still freshness-checked', () => {
|
|
const relativePath = '.agents/skills/gstack-ship/SKILL.md';
|
|
git('add', '--force', '--', relativePath);
|
|
try {
|
|
expect(checkGeneratedFreshness(repo, render, generated.artifacts).diagnostics.some(d => d.kind === 'stale' && d.relativePath === relativePath)).toBe(true);
|
|
} finally { git('update-index', '--force-remove', '--', relativePath); }
|
|
});
|
|
|
|
test('Git failures are errors rather than stale results', () => {
|
|
const empty = fs.mkdtempSync(path.join(base, 'not-a-repo-'));
|
|
const result = checkGeneratedFreshness(empty, render, generated.artifacts);
|
|
expect(result.diagnostics).toHaveLength(1);
|
|
expect(result.diagnostics[0].kind).toBe('error');
|
|
expect(result.diagnostics[0].message).toContain('git ls-files');
|
|
});
|
|
});
|
|
|
|
describe('shared content validators', () => {
|
|
const file = path.join(base, 'validation/SKILL.md');
|
|
const artifact: GeneratedArtifact = { relativePath: 'validation/SKILL.md', host: 'codex', kind: 'skill' };
|
|
const frontmatter = '---\nname: fixture\ndescription: fixture skill\n---\n';
|
|
beforeAll(() => fs.mkdirSync(path.dirname(file)));
|
|
|
|
for (const [content, message] of [
|
|
['body only', 'frontmatter'],
|
|
['---\nname: fixture\ndescription: broken: mapping\n---\nBody.', 'valid YAML'],
|
|
['---\nname: 123\ndescription: fixture skill\n---\nBody.', 'name must be a nonempty string'],
|
|
['---\nname: fixture\ndescription: [one, two]\n---\nBody.', 'description must be a nonempty string'],
|
|
['---\nname: fixture\ndescription: ""\n---\nBody.', 'description must be a nonempty string'],
|
|
[frontmatter + '```bash\n$B nonexistent-command\n```', 'unknown command'],
|
|
[frontmatter + '```bash\n$B snapshot --bogus\n```', 'Unknown snapshot flag'],
|
|
[frontmatter + 'Read ~/.claude/skills/gstack/SKILL.md', 'outside a bash block'],
|
|
]) {
|
|
test(`rejects ${message}`, () => {
|
|
fs.writeFileSync(file, content);
|
|
expect(validateGeneratedArtifact(base, artifact).some(d => d.message.includes(message))).toBe(true);
|
|
});
|
|
}
|
|
|
|
test('legitimate fallback paths in bash examples pass', () => {
|
|
fs.writeFileSync(file, frontmatter + '```bash\nROOT=~/.claude/skills/gstack\n$B snapshot -i\n```');
|
|
expect(validateGeneratedArtifact(base, artifact)).toEqual([]);
|
|
});
|
|
|
|
test('quoted names and multiline descriptions remain valid for every host', () => {
|
|
fs.writeFileSync(file, '---\nname: "custom-skill"\ndescription: |\n A legitimate multiline\n description: with a colon.\n---\nBody.');
|
|
for (const host of ALL_HOST_NAMES) {
|
|
expect(validateGeneratedArtifact(base, { ...artifact, host })).toEqual([]);
|
|
}
|
|
});
|
|
|
|
test('carved sections also validate commands without requiring frontmatter', () => {
|
|
fs.writeFileSync(file, '```bash\n$B snapshot --bogus\n```');
|
|
const diagnostics = validateGeneratedArtifact(base, { ...artifact, kind: 'section', host: 'claude' });
|
|
expect(diagnostics).toHaveLength(1);
|
|
expect(diagnostics[0].message).toContain('Unknown snapshot flag');
|
|
});
|
|
});
|