refactor(review): simplify pass over E (reuse, simplification, efficiency)
Quality only, no behaviour change (four cleanup reviewers, one implementer; npm test 2480/0 on the working tree): - threat-model.mjs splitBacked(): the one known_outside backing check of plan-gate (record and bare gate), verdict-gate and review-finalize, with one why-text; the engines' security keys derived from ENGINES; isSecurity. - coordinator-contract: "not a security engine" read from ENGINES (a string engine only), not the code-review literal. - review-rounds owns trailingBlock, findingsBlockSha, isMajor, isBlocker; review-answers imports them (review-rounds still imports nothing from it). prepare keeps the archive bytes it read instead of reading the previous archive again. - engine-compare exports rowIn and payloadEngine; finalize uses them. - plan-gate: one accepted_open builder; the stop-rule check hoisted; one top-level lookup for --record --brief. - security-engine: notFullShas(), runCli's usage flag, readScopeList shared with engine-findings; findReport and reviewRoundSummary module-private; two dead defaults gone. - tests: shared plan-gate harness and threat-model brief helpers; the [CNV] table cases call convertReport in-process, one CLI case per exit path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b94b060035
commit
f820081bdc
18 changed files with 332 additions and 373 deletions
81
tests/helpers/plan-gate-harness.mjs
Normal file
81
tests/helpers/plan-gate-harness.mjs
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
// tests/helpers/plan-gate-harness.mjs
|
||||
// The critic-round and CLI harness of the plan-gate tests
|
||||
// (tests/validators/plan-gate-diff-mode, -stop-rule and -threat-model):
|
||||
// rounds through the real recordVerdict and dedup on buildPlan() text, and
|
||||
// plan-gate.mjs run as a child in its own temp `git init` repo.
|
||||
|
||||
import { strict as assert } from 'node:assert';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { mkdtempSync, realpathSync, rmSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { dirname, join, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { recordVerdict, planHash, operativeText } from '../../lib/validators/plan-gate.mjs';
|
||||
import { dedupFindings } from '../../lib/review/plan-review-dedup.mjs';
|
||||
import { childEnv } from './child-env.mjs';
|
||||
|
||||
export const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..', '..');
|
||||
export const PATHS = [resolve('plan.md')];
|
||||
|
||||
/** The 1-based full-file line holding `s` (findIndex over the whole text). */
|
||||
export function at(text, s) {
|
||||
const n = text.split('\n').findIndex(l => l.includes(s)) + 1;
|
||||
assert.ok(n > 0, `the plan holds ${JSON.stringify(s)}`);
|
||||
return n;
|
||||
}
|
||||
|
||||
/** The base a round diffs against: the operative text the previous round reviewed. */
|
||||
export const baseOf = t => ({ sha256: planHash(t), text: operativeText(t) });
|
||||
|
||||
/** `rec(text, d, opts)`: one round as Phase 9 runs it, recorded at `now`, with the plan path known to the gate. */
|
||||
export function recorder(now) {
|
||||
return (text, d, opts = {}) => {
|
||||
const r = recordVerdict(text, d, { reviewed: planHash(text), planPaths: PATHS, now, ...opts });
|
||||
assert.equal(r.code, 0, r.message);
|
||||
return r;
|
||||
};
|
||||
}
|
||||
|
||||
/** Reviewer payloads through the real dedup. */
|
||||
export function dd({ pc = [], sg = [], pcPrev, sgPrev } = {}) {
|
||||
return dedupFindings([
|
||||
{ agent: 'plan-critic', payload: { findings: pc, ...(pcPrev ? { previous: pcPrev } : {}) } },
|
||||
{ agent: 'scope-guardian', payload: { findings: sg, ...(sgPrev ? { previous: sgPrev } : {}) } },
|
||||
]);
|
||||
}
|
||||
|
||||
/** A reviewer finding on plan.md under `rule_key`. */
|
||||
export const keyedFinding = (severity, line, text, rule_key, extra = {}) => ({ file: 'plan.md', line, rule_key, severity, text, ...extra });
|
||||
|
||||
export const R1_CHANGES = 'Add `run1()`';
|
||||
export const R2_CHANGES = '- **Changes:** Add `run2()` to `src/mod2.mjs`. (new file)';
|
||||
export const R2_EDITED = '- **Changes:** Add `run2()` and its error path to `src/mod2.mjs`. (new file)\n - `run2()` throws on empty input.';
|
||||
|
||||
/** Edit A: Step 2's Changes line becomes two lines (a two-line hunk, nothing above it moves). */
|
||||
export function editA(t) {
|
||||
assert.ok(t.includes(R2_CHANGES));
|
||||
return t.replace(R2_CHANGES, R2_EDITED);
|
||||
}
|
||||
|
||||
// ---- CLI ------------------------------------------------------------------------
|
||||
|
||||
export const GATE = join(ROOT, 'lib', 'validators', 'plan-gate.mjs');
|
||||
export const GIT_CLEAN = { GIT_DIR: undefined, GIT_WORK_TREE: undefined, GIT_INDEX_FILE: undefined };
|
||||
|
||||
/** plan-gate.mjs as a child in `cwd`, with `input` on stdin. */
|
||||
export function runGate(cwd, args, input) {
|
||||
const r = spawnSync(process.execPath, [GATE, ...args], { cwd, input, encoding: 'utf-8', env: childEnv(GIT_CLEAN) });
|
||||
return { code: r.status, out: r.stdout, err: r.stderr };
|
||||
}
|
||||
|
||||
/** The last non-empty output line, parsed. */
|
||||
export const lastJson = out => JSON.parse(out.split('\n').filter(l => l !== '').at(-1));
|
||||
|
||||
/** A fresh temp dir (real path), `git init`-ed; removed again when the init fails. */
|
||||
export function tempRepo(prefix) {
|
||||
const dir = realpathSync(mkdtempSync(join(tmpdir(), prefix)));
|
||||
const g = spawnSync('git', ['init', '-q'], { cwd: dir, encoding: 'utf-8', env: childEnv(GIT_CLEAN) });
|
||||
if (g.status !== 0) rmSync(dir, { recursive: true, force: true });
|
||||
assert.equal(g.status, 0, g.stderr);
|
||||
return dir;
|
||||
}
|
||||
41
tests/helpers/threat-model-brief.mjs
Normal file
41
tests/helpers/threat-model-brief.mjs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// tests/helpers/threat-model-brief.mjs
|
||||
// The brief fixture of the threat-model tests (tests/lib/threat-model and
|
||||
// tests/validators/brief-threat-model): a brief_version 2.2 brief with an
|
||||
// optional `## Threat Model` section before its Success Criteria.
|
||||
|
||||
export const OUTSIDE = "a local user who can already edit the repo's hooks";
|
||||
export const INSIDE = 'a crafted file name in a pull request reaches the shell';
|
||||
export const TM = `## Threat Model\n\n- Inside: ${INSIDE}\n- Outside: ${OUTSIDE}\n`;
|
||||
|
||||
/** The brief with `threat` (a `## Threat Model` section, or '') before its Success Criteria, of frontmatter `type`. */
|
||||
export const briefWith = (threat, type = 'trekbrief') => `---
|
||||
type: ${type}
|
||||
brief_version: "2.2"
|
||||
created: 2026-11-08
|
||||
task: "Add an upload hook"
|
||||
slug: upload-hook
|
||||
project_dir: .claude/projects/2026-11-08-upload-hook/
|
||||
research_topics: 0
|
||||
research_status: complete
|
||||
framing: new-direction
|
||||
---
|
||||
|
||||
# Task
|
||||
|
||||
## TL;DR
|
||||
|
||||
An upload hook.
|
||||
|
||||
## Intent
|
||||
|
||||
Uploads arrive from strangers.
|
||||
|
||||
## Goal
|
||||
|
||||
A hook that checks each upload.
|
||||
|
||||
${threat}
|
||||
## Success Criteria
|
||||
|
||||
- It checks.
|
||||
`;
|
||||
Loading…
Add table
Add a link
Reference in a new issue