* test(3582): failing-first cold-tree coverage and the seam drift lint On a plugin-channel install the compiled gsd-core/bin/lib/*.cjs are legitimately absent (ADR-457 build-at-publish; the npm package builds before publishing, a raw tree materialization never does). gsd-tools.cjs calls ensureRuntimeBuild() before requiring ./lib; no hook does, so the isolation guard's Cannot-find-module lands in its fail-closed catch and is misreported as an unreadable dispatch-isolation configuration, blocking every executor dispatch. These tests fail on that: cold-tree runs of the isolation guard, statusline, cursor guard and update worker, plus the seam's actionable build error surfacing instead of the generic misreport. Also adds the drift lint the acceptance criteria require, with a fixture proving it CAN fail — a guard never shown to fail is worthless. It is red here by design: it flags today's unfixed hooks, which is exactly the defect. * fix(3582): route every hook's compiled-module require through the self-heal seam RED proven at 5b174b0d: 11 failures — the cold-tree runs for the isolation guard, cursor guard and update worker, the fail-closed-with-actionable-message assertion, and the lint's own real-tree check. The compiled runtime library is produced by build:lib and gitignored (ADR-457, build-at-publish). The npm package builds before publishing; a plugin-marketplace or git-clone install materializes the raw tree and never does, so on that channel those modules are legitimately absent. The self-heal seam added by #2002 exists to heal exactly this, and the CLI entrypoint already calls it — no hook did. The isolation guard's Cannot-find-module therefore landed in its fail-closed catch and was reported as 'could not read or resolve dispatch-isolation configuration', so an ARTIFACT ABSENCE was misdiagnosed as an unreadable project config and every executor dispatch was blocked. All SEVEN affected files now call the seam before their first compiled require. The issue named four; a scan found six; implementing it surfaced a seventh — the shared isolation sentinel helper, used by BOTH guards, which requires two compiled modules itself and would have defeated the guards' own fix on a genuinely cold tree. Same defect class, so fixed here rather than left as a known-broken remainder. Failure posture is deliberately split by hook kind: - Gates (agent isolation guard, cursor subagent start) surface the seam's actionable build error distinctly instead of swallowing it into the generic text, and stay fail-closed — a genuinely unreadable project config still DENIES exactly as before. - Cosmetic and detached hooks (statusline, update worker, update check, update banner) DEGRADE rather than crash: the statusline draws on every render and the worker is a detached process, so a build failure there must not take down the prompt. The npm path is untouched: the seam's already-built fast path returns immediately, so prebuilt installs pay nothing and behave bit-for-bit as before. Adds a drift lint, wired into the CI lint chain, so the invariant is enforced rather than remembered — without it the next hook to add a compiled require reintroduces the class silently. It is proven able to fail: a fixture hook requiring a compiled module without the seam is flagged, and one that uses the seam is not. Verified directly — on the unfixed tree it named all seven offenders; with the fix it passes. While writing the lint's comment stripper, a naive whole-text block-comment regex ate its own fixture, because this repo's comments legitimately spell the compiled-lib glob whose star-slash reads as a comment opener. Rewritten as a line-based scanner with a regression test pinning that case. * fix(3582): test the three untested seam call sites and assert typed reason codes Two independent reviews converged on the same major gap: the fix wired the seam into seven files but only four had cold-tree tests. The adversarial pass put it plainly — deleting the shared isolation-sentinel helper's seam call would not have failed any test in the diff. That file was my own addition beyond the issue's four, so it shipped untested; that is now closed. - Shared isolation-sentinel helper: its seam call is only reached when .planning is NOT directly under cwd, and every existing cold-tree fixture puts it there, so the early return always fired first. Now covered, and proven load-bearing by mutation: with the call removed the spy records zero seam invocations and the test fails. - update-check hook and update-banner hook: cold-tree tests added asserting the DEGRADED VERDICT — the fallback cache filename, and silent suppression when the package name degrades to null — rather than merely 'did not throw'. The banner hook previously had no test file at all. Standards violation fixed: two tests asserted on free-form prose via assert.match against a JSON reason string, which CONTRIBUTING bans by name — its own BAD example is exactly that. The ESLint rule only covers readFileSync/spawnSync text, so tooling did not catch it. Both isolation guards now emit a machine-readable reason_code from a frozen enum, following the repo's existing REASON convention, and the tests assert that instead. The human-readable message is unchanged for operators; only the assertion target moved. The duplicated degrade boilerplate across the three cosmetic hooks was deliberately NOT extracted, and the reason is recorded at each site: both viable shapes — a path-parameterized helper, or a ceremony-only wrapper — defeat the drift lint's per-file literal co-occurrence check, so extracting would require the lint to special-case its own helper. Triplication is the lesser evil while the lint stays a co-occurrence scan. The lint's header now states what it does and does not catch (literal quoted requires only; hooks/ scan root), so a future reader does not over-trust a guard that a concatenated path or a require inside a non-hooks helper would evade. * chore(3582): regenerate the committed install-tree fixtures Adding a new shipped hook helper changed the install tree, and those fixtures are committed-and-derived (regen:derived / gen:install-tree), so 12 'install tree — <runtime>' tests failed on 541a1913. Regenerated rather than hand-edited. The delta across all 15 runtime fixtures is exactly two lines — the new helper under both its hooks/ and gsd-hooks/ install paths — and nothing else, so the regeneration pulled in no unrelated drift. This is the bookkeeping ripple a new file under hooks/ carries; it was not visible from lint:ci, which passed both before and after. * chore(3582): backfill changeset PR number (#3629) --------- Co-authored-by: sim <sim@local>
This commit is contained in:
@@ -88,6 +88,62 @@ describe('worker delegates the npm spawn (does not re-open the gate, #498)', ()
|
||||
});
|
||||
});
|
||||
|
||||
// ─── #3582: cold tree (no gsd-core/bin/lib/*.cjs) — degrade, not crash ─────
|
||||
//
|
||||
// gsd-core/bin/lib/semver-compare.cjs, package-identity.cjs, and (via
|
||||
// check-latest-version.cjs's own transitive requires) gsd-core/bin/lib/
|
||||
// cli-exit.cjs + shell-command-projection.cjs are tsc build artifacts
|
||||
// (ADR-457), gitignored and absent on a raw plugin-marketplace / git-clone
|
||||
// install that never ran `npm run build:lib`. This worker is a DETACHED
|
||||
// SessionStart background process (spawned with stdio: 'ignore' by
|
||||
// hooks/gsd-check-update.js) — before #3582 a missing library crashed the
|
||||
// worker at module load with no visible signal (stderr discarded by the
|
||||
// parent) and no cache-file write at all, so the statusline/banner would
|
||||
// silently never see an update signal. The fix wraps ensureRuntimeBuild()
|
||||
// and the three compiled-lib requires in one try/catch and degrades to
|
||||
// no-signal fallbacks (isSemverNewer -> false, checkLatestVersion -> not ok,
|
||||
// PACKAGE_NAME -> null) on failure — the worker still runs to completion and
|
||||
// writes a result cache record. Simulated hermetically via a fixture install
|
||||
// tree that copies hooks/ + the seam module but never gsd-core/bin/lib/ or
|
||||
// tsconfig.build.json (tests/helpers/cold-runtime-lib-fixture.cjs) — the REAL
|
||||
// gsd-core/bin/lib/ is never touched.
|
||||
{
|
||||
const { describe, test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { runHook: runHookSeam } = require('./helpers/process-seam.cjs');
|
||||
const { buildColdInstallTree } = require('./helpers/cold-runtime-lib-fixture.cjs');
|
||||
const { createTempDir, cleanup } = require('./helpers.cjs');
|
||||
|
||||
describe('gsd-check-update-worker.js: #3582 cold tree — degrade, not crash', () => {
|
||||
test('missing compiled runtime library -> worker still writes a degraded result cache, no crash', (t) => {
|
||||
const cold = buildColdInstallTree();
|
||||
t.after(cold.cleanup);
|
||||
const cacheDir = createTempDir('gsd-worker-cold-');
|
||||
t.after(() => cleanup(cacheDir));
|
||||
const cacheFile = path.join(cacheDir, 'cache.json');
|
||||
|
||||
const env = {
|
||||
...process.env,
|
||||
GSD_CACHE_FILE: cacheFile,
|
||||
GSD_PROJECT_VERSION_FILE: path.join(cacheDir, 'no-such-project', 'VERSION'),
|
||||
GSD_GLOBAL_VERSION_FILE: path.join(cacheDir, 'no-such-global', 'VERSION'),
|
||||
};
|
||||
const r = runHookSeam(path.join(cold.hooksDir, 'gsd-check-update-worker.js'), [], {
|
||||
env,
|
||||
timeoutMs: 8000,
|
||||
});
|
||||
assert.equal(r.exitCode, 0, `worker must exit 0 on a build failure; stderr: ${r.stderr}`);
|
||||
assert.ok(fs.existsSync(cacheFile), 'worker must still reach the end and write a cache record');
|
||||
const cache = JSON.parse(fs.readFileSync(cacheFile, 'utf8'));
|
||||
assert.equal(cache.package_name, null, 'degraded package_name must be null (no-signal, never a stale/foreign value)');
|
||||
assert.ok(!cache.update_available, 'degraded update_available must be falsy');
|
||||
assert.equal(cache.installed, '0.0.0', 'installed detection is unaffected by the compiled-lib degrade');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// ────────────────────────────────────────────────────────────────────────
|
||||
// Folded from tests/bug-2992-check-latest-version.test.cjs — consolidation epic #1969 (B5 #1974)
|
||||
@@ -783,6 +839,58 @@ describe('gsd-update-banner.js end-to-end', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ─── #3582: cold tree (no gsd-core/bin/lib/*.cjs) — degrade, not crash ─────
|
||||
//
|
||||
// gsd-core/bin/lib/package-identity.cjs is a tsc build artifact (ADR-457),
|
||||
// gitignored and absent on a raw plugin-marketplace / git-clone install that
|
||||
// never ran `npm run build:lib`. This is an opt-in SessionStart hook — a
|
||||
// build failure must degrade (PACKAGE_NAME stays null), not crash session
|
||||
// start. The DEGRADED VERDICT this locks: buildBannerOutput's own lineage
|
||||
// guard (`!cache.package_name || cache.package_name !== PACKAGE_NAME`)
|
||||
// unconditionally distrusts ANY cache once PACKAGE_NAME is null, so even a
|
||||
// cache written by a healthy worker (real package_name, update_available:
|
||||
// true) must be suppressed rather than surfaced — the hook stays SILENT
|
||||
// (exit 0, empty stdout), never a crash and never a stale/wrong banner.
|
||||
// Simulated hermetically via tests/helpers/cold-runtime-lib-fixture.cjs — the
|
||||
// REAL gsd-core/bin/lib/ is never touched.
|
||||
describe('gsd-update-banner.js: #3582 cold tree — degrades to silent, never crashes', () => {
|
||||
const { buildColdInstallTree } = require('./helpers/cold-runtime-lib-fixture.cjs');
|
||||
|
||||
test('missing compiled runtime library -> exits 0 with empty stdout even for an otherwise-valid update-available cache', (t) => {
|
||||
const cold = buildColdInstallTree();
|
||||
t.after(cold.cleanup);
|
||||
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-banner-cold-home-'));
|
||||
t.after(() => cleanup(home));
|
||||
fs.mkdirSync(path.join(home, '.cache', 'gsd'), { recursive: true });
|
||||
// The generic fallback filename the hook's own #3582 degrade uses when
|
||||
// package-identity.cjs cannot be built (mirrors gsd-check-update.js's
|
||||
// identical fallback literal) — this is the SAME cache path a degraded
|
||||
// worker would also have written to.
|
||||
fs.writeFileSync(
|
||||
path.join(home, '.cache', 'gsd', 'gsd-update-check.json'),
|
||||
JSON.stringify({
|
||||
update_available: true,
|
||||
installed: '1.39.0',
|
||||
latest: '1.40.0',
|
||||
package_name: '@opengsd/gsd-core',
|
||||
}),
|
||||
);
|
||||
|
||||
const r = seamRunHook(path.join(cold.hooksDir, 'gsd-update-banner.js'), [], {
|
||||
env: { ...process.env, HOME: home, USERPROFILE: home },
|
||||
timeoutMs: 10_000,
|
||||
});
|
||||
|
||||
assert.equal(r.exitCode, 0, `hook must exit 0 on a build failure; stderr: ${r.stderr}`);
|
||||
assert.equal(
|
||||
r.stdout.trim(),
|
||||
'',
|
||||
'a cold tree must silently suppress the banner (PACKAGE_NAME degrades to null, ' +
|
||||
'so the lineage guard distrusts every cache) rather than crash or print stale content',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Install.js wiring: prompt + SessionStart entry registration ────────────
|
||||
//
|
||||
// These tests load bin/install.js as a module via GSD_TEST_MODE and assert on
|
||||
|
||||
Reference in New Issue
Block a user