@descent-vtt/spec-harness 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/git.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAU9C,gFAAgF;AAChF,MAAM,UAAU,GAAG,CAAC,IAAuB,EAAE,GAAW,EAAE,KAAc;IACtE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,KAAK,GAAG,QAAQ,CACpB,KAAK,EACL,CAAC,GAAG,IAAI,CAAC,EACT,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,EAC1E,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;YACxB,MAAM,IAAI,GAAG,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAQ,KAA4B,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAE,KAA0B,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACnI,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QACpC,CAAC,CACF,CAAC;QACF,IAAI,KAAK,KAAK,SAAS;YAAE,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACL,CAAC;AAED,KAAK,UAAU,KAAK,CAAC,IAAuB,EAAE,GAAW;IACvD,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACjC,OAAO,GAAG,CAA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AgB,EAAE,eAAe,EAAE,OAAO,EAAE,GAAG,CAAC,EACjH,GAAG,CACJ,CAAC;IACF,MAAM,IAAI,GAAG,GAAG,GAAG,CAAC,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,CAAC;IAC5C,MAAM,SAAS,GAAG,gCAAgC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IAC3E,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,KAAK,CAAC,IAAI,SAAS,KAAK,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;AAC7G,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAY,EAAE,GAAW,EAAE,GAAW;IACtE,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IAClF,IAAI,GAAG,CAAC,IAAI,KAAK,CAAC;QAAE,MAAM,IAAI,QAAQ,CAAC,4BAA4B,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAC1F,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAY,EAAE,GAAW;IAC5D,MAAM,GAAG,CAAC,CAAC,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["/**\n * The edge where the harness meets git.\n *\n * Reads, except for two things ADR-0003 allows and bounds: a temporary\n * worktree, added and always removed by the sandbox, and nothing else. Every\n * call is an argument vector, never a shell string, so a path or a ref cannot\n * become a command.\n */\n\nimport { execFile } from 'node:child_process';\n\nimport type { FileChange } from './types.js';\n\nexport interface Run {\n readonly code: number;\n readonly stdout: string;\n readonly stderr: string;\n}\n\n/** Runs git and answers whatever it answered; a missing git is a code of -1. */\nexport function git(args: readonly string[], cwd: string, input?: string): Promise<Run> {\n return new Promise((resolve) => {\n const child = execFile(\n 'git',\n [...args],\n { cwd, maxBuffer: 256 * 1024 * 1024, encoding: 'utf8', windowsHide: true },\n (error, stdout, stderr) => {\n const code = error === null ? 0 : typeof (error as { code?: unknown }).code === 'number' ? ((error as { code: number }).code) : -1;\n resolve({ code, stdout, stderr });\n },\n );\n if (input !== undefined) child.stdin?.end(input);\n });\n}\n\nasync function value(args: readonly string[], cwd: string): Promise<string | null> {\n const run = await git(args, cwd);\n return run.code === 0 ? run.stdout.trim() : null;\n}\n\nexport class GitError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'GitError';\n }\n}\n\n/** The top of the work tree holding `cwd`, POSIX-separated, or `null` outside one. */\nexport async function workTreeRoot(cwd: string): Promise<string | null> {\n return value(['rev-parse', '--show-toplevel'], cwd);\n}\n\n/** The git directory every worktree of this repository shares. */\nexport async function commonDirectory(cwd: string): Promise<string | null> {\n return value(['rev-parse', '--path-format=absolute', '--git-common-dir'], cwd);\n}\n\n/**\n * Where git runs the hook `name` from, absolute: `core.hooksPath` read as git\n * reads it - relative to the work tree, absolute, or under `~` - and a linked\n * worktree's shared hooks. `null` when git cannot say, before 2.31.\n */\nexport async function hookPath(name: string, cwd: string): Promise<string | null> {\n return value(['rev-parse', '--path-format=absolute', '--git-path', `hooks/${name}`], cwd);\n}\n\n/** The checked-out branch's short name, or `null` on a detached head. */\nexport async function currentBranch(cwd: string): Promise<string | null> {\n return value(['symbolic-ref', '--quiet', '--short', 'HEAD'], cwd);\n}\n\n/** The remote's default branch as a local ref, such as `origin/main`, or `null`. */\nexport async function remoteDefault(cwd: string): Promise<string | null> {\n return value(['symbolic-ref', '--quiet', '--short', 'refs/remotes/origin/HEAD'], cwd);\n}\n\n/** Every local branch, by its short name. */\nexport async function localBranches(cwd: string): Promise<string[]> {\n const listed = await value(['for-each-ref', '--format=%(refname:short)', 'refs/heads/'], cwd);\n return listed === null || listed === '' ? [] : listed.split('\\n').map((name) => name.trim());\n}\n\nexport async function revision(ref: string, cwd: string): Promise<string | null> {\n return value(['rev-parse', '--verify', '--quiet', `${ref}^{commit}`], cwd);\n}\n\nexport async function mergeBase(a: string, b: string, cwd: string): Promise<string | null> {\n return value(['merge-base', a, b], cwd);\n}\n\n/** Parses `git diff --name-status -z` output. */\nexport function parseNameStatus(output: string): FileChange[] {\n const fields = output.split('\\0');\n const out: FileChange[] = [];\n for (let i = 0; i < fields.length; ) {\n const code = fields[i] ?? '';\n if (code === '') {\n i += 1;\n continue;\n }\n const status = code.charAt(0) as FileChange['status'];\n if (status === 'R' || status === 'C') {\n out.push({ status, from: fields[i + 1] ?? '', path: fields[i + 2] ?? '' });\n i += 3;\n } else {\n out.push({ status, path: fields[i + 1] ?? '' });\n i += 2;\n }\n }\n return out;\n}\n\n/** The files changed from one revision to another, renames found. */\nexport async function changes(from: string, to: string, cwd: string): Promise<FileChange[]> {\n const run = await git(['diff', '--name-status', '-z', '--find-renames', '--no-color', from, to, '--'], cwd);\n if (run.code !== 0) throw new GitError(`git diff ${from} ${to} failed: ${run.stderr.trim()}`);\n return parseNameStatus(run.stdout);\n}\n\n/** The files a commit would change: what is staged. */\nexport async function stagedChanges(cwd: string): Promise<FileChange[]> {\n const run = await git(['diff', '--cached', '--name-status', '-z', '--find-renames', '--no-color', '--'], cwd);\n if (run.code !== 0) throw new GitError(`git diff --cached failed: ${run.stderr.trim()}`);\n return parseNameStatus(run.stdout);\n}\n\n/** A file's content at a revision, or `null` when it does not exist there. */\nexport async function show(ref: string, path: string, cwd: string): Promise<string | null> {\n const run = await git(['show', `${ref}:${path}`], cwd);\n return run.code === 0 ? run.stdout : null;\n}\n\n/**\n * The commit that last changed one line of a file, as of a revision, or of\n * the working tree when `ref` is `null` - where a line nobody committed yet\n * belongs to the all-zero commit.\n */\nexport async function blameLine(ref: string | null, path: string, line: number, cwd: string): Promise<string | null> {\n const run = await git(['blame', '--porcelain', '-L', `${line},${line}`, ...(ref === null ? [] : [ref]), '--', path], cwd);\n if (run.code !== 0) return null;\n const sha = /^([0-9a-f]{40,64}) /.exec(run.stdout)?.[1];\n return sha ?? null;\n}\n\nexport interface Signature {\n readonly good: boolean;\n /** The allowed signer's principal, for a good signature. */\n readonly principal: string | null;\n readonly detail: string;\n}\n\n/**\n * Whether a commit carries a good SSH signature by a principal in the given\n * allowed-signers file. The file is passed in, never read from the commit's\n * own tree: a round cannot vouch for itself (ADR-0006).\n */\nexport async function verifyCommit(sha: string, allowedSignersFile: string, cwd: string): Promise<Signature> {\n const run = await git(\n ['-c', `gpg.ssh.allowedSignersFile=${allowedSignersFile}`, '-c', 'gpg.format=ssh', 'verify-commit', '--raw', sha],\n cwd,\n );\n const text = `${run.stderr}\\n${run.stdout}`;\n const principal = /Good \"git\" signature for (\\S+)/.exec(text)?.[1] ?? null;\n return { good: run.code === 0 && principal !== null, principal, detail: text.trim().split('\\n')[0] ?? '' };\n}\n\nexport async function addWorktree(path: string, rev: string, cwd: string): Promise<void> {\n const run = await git(['worktree', 'add', '--detach', '--force', path, rev], cwd);\n if (run.code !== 0) throw new GitError(`git worktree add failed: ${run.stderr.trim()}`);\n}\n\n/**\n * Forgets the worktree at `path`, and no other, once its directory is\n * deleted. Git refuses to remove a worktree whose directory has lost its\n * `.git` file, and removes its record of one whose directory is gone, found by\n * the path it was added at: `git worktree prune` would also forget every other\n * worktree git has lost track of, the person's among them.\n */\nexport async function removeWorktree(path: string, cwd: string): Promise<void> {\n await git(['worktree', 'remove', '--force', path], cwd);\n}\n"]}
1
+ {"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAU9C,gFAAgF;AAChF,MAAM,UAAU,GAAG,CAAC,IAA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AAC,CAAW,CAAC;IACpD,0EAA0E;IAC1E,wEAAwE;IACxE,OAAO,GAAG,CAAC,IAAI,KAAK,CAAC,IAAI,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAClI,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAY,EAAE,GAAW,EAAE,GAAW;IACtE,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IAClF,IAAI,GAAG,CAAC,IAAI,KAAK,CAAC;QAAE,MAAM,IAAI,QAAQ,CAAC,4BAA4B,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAC1F,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAY,EAAE,GAAW;IAC5D,MAAM,GAAG,CAAC,CAAC,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["/**\n * The edge where the harness meets git.\n *\n * Reads, except for two things ADR-0003 allows and bounds: a temporary\n * worktree, added and always removed by the sandbox, and nothing else. Every\n * call is an argument vector, never a shell string, so a path or a ref cannot\n * become a command.\n */\n\nimport { execFile } from 'node:child_process';\n\nimport type { FileChange } from './types.js';\n\nexport interface Run {\n readonly code: number;\n readonly stdout: string;\n readonly stderr: string;\n}\n\n/** Runs git and answers whatever it answered; a missing git is a code of -1. */\nexport function git(args: readonly string[], cwd: string): Promise<Run> {\n return new Promise((resolve) => {\n // windowsHide only keeps a console window from flashing up on Windows,\n // and the sweep runs on Linux, where its mutant is equivalent.\n execFile('git', [...args], { cwd, maxBuffer: 256 * 1024 * 1024, encoding: 'utf8', windowsHide: true }, (error, stdout, stderr) => {\n // Every caller tells 0 from any other code, never one failure from\n // another, so which code a failure gets is equivalent to its mutants.\n const code = error === null ? 0 : typeof (error as { code?: unknown }).code === 'number' ? (error as { code: number }).code : -1;\n resolve({ code, stdout, stderr });\n });\n });\n}\n\nasync function value(args: readonly string[], cwd: string): Promise<string | null> {\n const run = await git(args, cwd);\n return run.code === 0 ? run.stdout.trim() : null;\n}\n\nexport class GitError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'GitError';\n }\n}\n\n/** The top of the work tree holding `cwd`, POSIX-separated, or `null` outside one. */\nexport async function workTreeRoot(cwd: string): Promise<string | null> {\n return value(['rev-parse', '--show-toplevel'], cwd);\n}\n\n/** The git directory every worktree of this repository shares. */\nexport async function commonDirectory(cwd: string): Promise<string | null> {\n return value(['rev-parse', '--path-format=absolute', '--git-common-dir'], cwd);\n}\n\n/**\n * Where git runs the hook `name` from, absolute: `core.hooksPath` read as git\n * reads it - relative to the work tree, absolute, or under `~` - and a linked\n * worktree's shared hooks. `null` when git cannot say, before 2.31.\n */\nexport async function hookPath(name: string, cwd: string): Promise<string | null> {\n return value(['rev-parse', '--path-format=absolute', '--git-path', `hooks/${name}`], cwd);\n}\n\n/** The checked-out branch's short name, or `null` on a detached head. */\nexport async function currentBranch(cwd: string): Promise<string | null> {\n return value(['symbolic-ref', '--quiet', '--short', 'HEAD'], cwd);\n}\n\n/** The remote's default branch as a local ref, such as `origin/main`, or `null`. */\nexport async function remoteDefault(cwd: string): Promise<string | null> {\n return value(['symbolic-ref', '--quiet', '--short', 'refs/remotes/origin/HEAD'], cwd);\n}\n\n/** Every local branch, by its short name. */\nexport async function localBranches(cwd: string): Promise<string[]> {\n const listed = await value(['for-each-ref', '--format=%(refname:short)', 'refs/heads/'], cwd);\n // for-each-ref fails only where git itself does, outside a repository,\n // where init never runs: the null check is there for the type.\n return listed === null || listed === '' ? [] : listed.split('\\n');\n}\n\nexport async function revision(ref: string, cwd: string): Promise<string | null> {\n return value(['rev-parse', '--verify', '--quiet', `${ref}^{commit}`], cwd);\n}\n\nexport async function mergeBase(a: string, b: string, cwd: string): Promise<string | null> {\n return value(['merge-base', a, b], cwd);\n}\n\n/** Parses `git diff --name-status -z` output. */\nexport function parseNameStatus(output: string): FileChange[] {\n const fields = output.split('\\0');\n const out: FileChange[] = [];\n for (let i = 0; i < fields.length; ) {\n const code = fields[i] as string;\n if (code === '') {\n i += 1;\n continue;\n }\n const status = code.charAt(0) as FileChange['status'];\n if (status === 'R' || status === 'C') {\n out.push({ status, from: fields[i + 1] ?? '', path: fields[i + 2] ?? '' });\n i += 3;\n } else {\n out.push({ status, path: fields[i + 1] ?? '' });\n i += 2;\n }\n }\n return out;\n}\n\n/** The files changed from one revision to another, renames found. */\nexport async function changes(from: string, to: string, cwd: string): Promise<FileChange[]> {\n const run = await git(['diff', '--name-status', '-z', '--find-renames', '--no-color', from, to, '--'], cwd);\n if (run.code !== 0) throw new GitError(`git diff ${from} ${to} failed: ${run.stderr.trim()}`);\n return parseNameStatus(run.stdout);\n}\n\n/** The files a commit would change: what is staged. */\nexport async function stagedChanges(cwd: string): Promise<FileChange[]> {\n const run = await git(['diff', '--cached', '--name-status', '-z', '--find-renames', '--no-color', '--'], cwd);\n if (run.code !== 0) throw new GitError(`git diff --cached failed: ${run.stderr.trim()}`);\n return parseNameStatus(run.stdout);\n}\n\n/** A file's content at a revision, or `null` when it does not exist there. */\nexport async function show(ref: string, path: string, cwd: string): Promise<string | null> {\n const run = await git(['show', `${ref}:${path}`], cwd);\n return run.code === 0 ? run.stdout : null;\n}\n\n/** Whether a commit id from {@link blameLine} is the all-zero one of a line nobody committed. */\nexport function isUncommitted(sha: string): boolean {\n return /^0+$/.test(sha);\n}\n\n/**\n * The commit that last changed one line of a file, as of a revision, or of\n * the working tree when `ref` is `null` - where a line nobody committed yet\n * belongs to the all-zero commit.\n */\nexport async function blameLine(ref: string | null, path: string, line: number, cwd: string): Promise<string | null> {\n const run = await git(['blame', '--porcelain', '-L', `${line},${line}`, ...(ref === null ? [] : [ref]), '--', path], cwd);\n // A blame that fails prints nothing on stdout, which names no commit. Its\n // output opens with the commit, so the anchor is equivalent to its mutant.\n const sha = /^([0-9a-f]{40,64}) /.exec(run.stdout)?.[1];\n return sha ?? null;\n}\n\n/** A good signature names its allowed signer's principal; any other names none. */\nexport type Signature =\n | { readonly good: true; readonly principal: string; readonly detail: string }\n | { readonly good: false; readonly principal: null; readonly detail: string };\n\n/**\n * Whether a commit carries a good SSH signature by a principal in the given\n * allowed-signers file. The file is passed in, never read from the commit's\n * own tree: a round cannot vouch for itself (ADR-0006).\n */\nexport async function verifyCommit(sha: string, allowedSignersFile: string, cwd: string): Promise<Signature> {\n const run = await git(\n ['-c', `gpg.ssh.allowedSignersFile=${allowedSignersFile}`, '-c', 'gpg.format=ssh', 'verify-commit', '--raw', sha],\n cwd,\n );\n const text = `${run.stderr}\\n${run.stdout}`;\n const principal = /Good \"git\" signature for (\\S+)/.exec(text)?.[1];\n // git writes the check to stderr, so the trim changes the first line only\n // for output on stdout alone, which verify-commit does not print; and split\n // always answers a first part.\n const detail = text.trim().split('\\n')[0] as string;\n // git exits 0 only for a signature by a listed principal, which it names:\n // either condition alone is equivalent to both, and both trust neither.\n return run.code === 0 && principal !== undefined ? { good: true, principal, detail } : { good: false, principal: null, detail };\n}\n\nexport async function addWorktree(path: string, rev: string, cwd: string): Promise<void> {\n const run = await git(['worktree', 'add', '--detach', '--force', path, rev], cwd);\n if (run.code !== 0) throw new GitError(`git worktree add failed: ${run.stderr.trim()}`);\n}\n\n/**\n * Forgets the worktree at `path`, and no other, once its directory is\n * deleted. Git refuses to remove a worktree whose directory has lost its\n * `.git` file, and removes its record of one whose directory is gone, found by\n * the path it was added at: `git worktree prune` would also forget every other\n * worktree git has lost track of, the person's among them.\n */\nexport async function removeWorktree(path: string, cwd: string): Promise<void> {\n await git(['worktree', 'remove', '--force', path], cwd);\n}\n"]}
package/dist/plugin.js CHANGED
@@ -22,7 +22,11 @@ import { rulingFor } from './guard.js';
22
22
  import { createReader } from './reader.js';
23
23
  import { checkRulings, resolveBase } from './round.js';
24
24
  import { createSiblings } from './siblings.js';
25
- /** Paths a finding names, in either of the shapes spec-brief reports them. */
25
+ /**
26
+ * Paths a finding names, in either of the shapes spec-brief reports them. A
27
+ * finding with neither names none, and a path no ruling names is waived for
28
+ * none, so the empty list is equivalent to its mutant.
29
+ */
26
30
  function pathsOf(finding) {
27
31
  if (finding.path !== undefined)
28
32
  return [finding.path];
@@ -30,11 +34,15 @@ function pathsOf(finding) {
30
34
  }
31
35
  export async function waive(context) {
32
36
  const protectedPaths = context.findings.filter((finding) => finding.rule === 'protected-file').flatMap(pathsOf);
37
+ // Asking git about nothing waives nothing: this saves the asking, and its
38
+ // mutant is equivalent.
33
39
  if (protectedPaths.length === 0)
34
40
  return [];
35
41
  const { config } = await loadConfig(context.root);
36
42
  const workspace = {
37
43
  root: context.root,
44
+ // spec-brief runs in a work tree, where git always names the common
45
+ // directory; the fallback is there for the type.
38
46
  commonDir: (await commonDirectory(context.root)) ?? `${context.root}/.git`,
39
47
  config,
40
48
  siblings: createSiblings(context.root, config),
@@ -42,22 +50,7 @@ export async function waive(context) {
42
50
  cwd: context.root,
43
51
  };
44
52
  const base = await resolveBase(workspace, context.base ?? undefined);
45
- const brief = {
46
- id: context.brief.id ?? context.brief.file,
47
- file: context.brief.file,
48
- title: null,
49
- phase: 'live',
50
- status: null,
51
- type: null,
52
- wave: null,
53
- dependsOn: [],
54
- affectedFiles: [],
55
- protectedFiles: [],
56
- tasks: { total: 0, checked: 0 },
57
- ready: false,
58
- waitingOn: [],
59
- };
60
- const { verified } = await checkRulings(workspace, brief, context.brief.text, createReader(), base);
53
+ const { verified } = await checkRulings(workspace, { file: context.brief.file }, context.brief.text, createReader(), base);
61
54
  const waivers = [];
62
55
  for (const path of protectedPaths) {
63
56
  const ruling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AC,CAAC;QACvH,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,wGAAwG;AACxG,MAAM,CAAC,OAAO,UAAU,iBAAiB;IACvC,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;AACpD,CAAC","sourcesContent":["/**\n * The spec-brief plugin: signed rulings, read where spec-brief decides.\n *\n * spec-brief's archive refuses a round that changed a file its brief protects.\n * When a person has ruled that the round may change it, and signed the ruling\n * (ADR-0006), the refusal is lifted - but spec-brief does not read signatures,\n * and should not: the tool that defines a format ships the check for it\n * (spec-brief ADR-0007). So the check ships here, and spec-brief asks it\n * through its plugin `waive` hook, once its configuration loads the plugin,\n * as `spec-harness init` writes it:\n *\n * ```json\n * { \"plugins\": [\"@descent-vtt/spec-harness/spec-brief-plugin\"] }\n * ```\n *\n * It waives a `protected-file` refusal for a path a verified `allow` ruling\n * names, and nothing else. A ruling that does not verify waives nothing.\n */\n\nimport { loadConfig } from './fs.js';\nimport { commonDirectory, currentBranch } from './git.js';\nimport { rulingFor } from './guard.js';\nimport { createReader } from './reader.js';\nimport { checkRulings, resolveBase } from './round.js';\nimport { createSiblings } from './siblings.js';\nimport type { BriefRow } from './types.js';\nimport type { Workspace } from './workspace.js';\n\nexport interface WaiveContext {\n readonly root: string;\n /** spec-brief passes a `null` id for a brief it could not name; its file still identifies it. */\n readonly brief: { readonly id: string | null; readonly file: string; readonly text: string };\n readonly findings: readonly { readonly rule: string; readonly path?: string | undefined; readonly paths?: readonly string[] | undefined }[];\n readonly base: string | null;\n readonly commit: string | null;\n}\n\nexport interface Waiver {\n readonly rule: string;\n readonly path: string;\n readonly reason: string;\n}\n\n/** Paths a finding names, in either of the shapes spec-brief reports them. */\nfunction pathsOf(finding: WaiveContext['findings'][number]): string[] {\n if (finding.path !== undefined) return [finding.path];\n return [...(finding.paths ?? [])];\n}\n\nexport async function waive(context: WaiveContext): Promise<Waiver[]> {\n const protectedPaths = context.findings.filter((finding) => finding.rule === 'protected-file').flatMap(pathsOf);\n if (protectedPaths.length === 0) return [];\n const { config } = await loadConfig(context.root);\n const workspace: Workspace = {\n root: context.root,\n commonDir: (await commonDirectory(context.root)) ?? `${context.root}/.git`,\n config,\n siblings: createSiblings(context.root, config),\n branch: await currentBranch(context.root),\n cwd: context.root,\n };\n const base = await resolveBase(workspace, context.base ?? undefined);\n const brief: BriefRow = {\n id: context.brief.id ?? context.brief.file,\n file: context.brief.file,\n title: null,\n phase: 'live',\n status: null,\n type: null,\n wave: null,\n dependsOn: [],\n affectedFiles: [],\n protectedFiles: [],\n tasks: { total: 0, checked: 0 },\n ready: false,\n waitingOn: [],\n };\n const { verified } = await checkRulings(workspace, brief, context.brief.text, createReader(), base);\n const waivers: Waiver[] = [];\n for (const path of protectedPaths) {\n const ruling = rulingFor(verified, path);\n if (ruling !== undefined) {\n waivers.push({ rule: 'protected-file', path, reason: `ruling ${ruling.id}, signed by ${ruling.signer}, allows it` });\n }\n }\n return waivers;\n}\n\n/** The plugin, as spec-brief loads it: a function of its options returning `{ name, rules, waive }`. */\nexport default function specHarnessPlugin(): { name: string; rules: readonly never[]; waive: typeof waive } {\n return { name: 'spec-harness', rules: [], waive };\n}\n"]}
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAkB/C;;;;GAIG;AACH,SAAS,OAAO,CA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E,YAAY,EAAE,EAAE,IAAI,CAAC,CAAC;IAC3H,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,KAAK,MAAM,IAAI,IAAI,cAAc,EAAE,CAAC;QAClC,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACzC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,MAAM,CAAC,EAAE,eAAe,MAAM,CAAC,MAAM,aAAa,EAAE,CAAC,CAAC;QACvH,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,wGAAwG;AACxG,MAAM,CAAC,OAAO,UAAU,iBAAiB;IACvC,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;AACpD,CAAC","sourcesContent":["/**\n * The spec-brief plugin: signed rulings, read where spec-brief decides.\n *\n * spec-brief's archive refuses a round that changed a file its brief protects.\n * When a person has ruled that the round may change it, and signed the ruling\n * (ADR-0006), the refusal is lifted - but spec-brief does not read signatures,\n * and should not: the tool that defines a format ships the check for it\n * (spec-brief ADR-0007). So the check ships here, and spec-brief asks it\n * through its plugin `waive` hook, once its configuration loads the plugin,\n * as `spec-harness init` writes it:\n *\n * ```json\n * { \"plugins\": [\"@descent-vtt/spec-harness/spec-brief-plugin\"] }\n * ```\n *\n * It waives a `protected-file` refusal for a path a verified `allow` ruling\n * names, and nothing else. A ruling that does not verify waives nothing.\n */\n\nimport { loadConfig } from './fs.js';\nimport { commonDirectory, currentBranch } from './git.js';\nimport { rulingFor } from './guard.js';\nimport { createReader } from './reader.js';\nimport { checkRulings, resolveBase } from './round.js';\nimport { createSiblings } from './siblings.js';\nimport type { Workspace } from './workspace.js';\n\nexport interface WaiveContext {\n readonly root: string;\n /** spec-brief passes a `null` id for a brief it could not name; its file still identifies it. */\n readonly brief: { readonly id: string | null; readonly file: string; readonly text: string };\n readonly findings: readonly { readonly rule: string; readonly path?: string | undefined; readonly paths?: readonly string[] | undefined }[];\n readonly base: string | null;\n readonly commit: string | null;\n}\n\nexport interface Waiver {\n readonly rule: string;\n readonly path: string;\n readonly reason: string;\n}\n\n/**\n * Paths a finding names, in either of the shapes spec-brief reports them. A\n * finding with neither names none, and a path no ruling names is waived for\n * none, so the empty list is equivalent to its mutant.\n */\nfunction pathsOf(finding: WaiveContext['findings'][number]): string[] {\n if (finding.path !== undefined) return [finding.path];\n return [...(finding.paths ?? [])];\n}\n\nexport async function waive(context: WaiveContext): Promise<Waiver[]> {\n const protectedPaths = context.findings.filter((finding) => finding.rule === 'protected-file').flatMap(pathsOf);\n // Asking git about nothing waives nothing: this saves the asking, and its\n // mutant is equivalent.\n if (protectedPaths.length === 0) return [];\n const { config } = await loadConfig(context.root);\n const workspace: Workspace = {\n root: context.root,\n // spec-brief runs in a work tree, where git always names the common\n // directory; the fallback is there for the type.\n commonDir: (await commonDirectory(context.root)) ?? `${context.root}/.git`,\n config,\n siblings: createSiblings(context.root, config),\n branch: await currentBranch(context.root),\n cwd: context.root,\n };\n const base = await resolveBase(workspace, context.base ?? undefined);\n const { verified } = await checkRulings(workspace, { file: context.brief.file }, context.brief.text, createReader(), base);\n const waivers: Waiver[] = [];\n for (const path of protectedPaths) {\n const ruling = rulingFor(verified, path);\n if (ruling !== undefined) {\n waivers.push({ rule: 'protected-file', path, reason: `ruling ${ruling.id}, signed by ${ruling.signer}, allows it` });\n }\n }\n return waivers;\n}\n\n/** The plugin, as spec-brief loads it: a function of its options returning `{ name, rules, waive }`. */\nexport default function specHarnessPlugin(): { name: string; rules: readonly never[]; waive: typeof waive } {\n return { name: 'spec-harness', rules: [], waive };\n}\n"]}
package/dist/premises.js CHANGED
@@ -19,6 +19,7 @@
19
19
  * A premise spec-guard cannot read is checked by nothing, and is a warning,
20
20
  * as it is in the audit: `--strict` fails the run on it.
21
21
  */
22
+ import { readGuardRun } from './answers.js';
22
23
  import { isPremise, premiseFinding, unreadablePremiseFinding } from './audit.js';
23
24
  import { briefIdFromBranch } from './branch.js';
24
25
  import { findActive } from './briefs.js';
@@ -32,7 +33,7 @@ export async function premisesCommand(options, io) {
32
33
  const reader = createReader();
33
34
  const briefs = await workspace.siblings.briefs();
34
35
  const live = briefs.filter((brief) => brief.phase === 'live');
35
- const fromBranch = workspace.branch === null ? null : briefIdFromBranch(workspace.config.branches, workspace.branch);
36
+ const fromBranch = briefIdFromBranch(workspace.config.branches, workspace.branch);
36
37
  const active = findActive(briefs, { flag: options.brief, environment: io.env['SPEC_BRIEF'], branch: fromBranch });
37
38
  const round = active.kind === 'found' ? active.brief.file : null;
38
39
  if (live.length === 0) {
@@ -53,14 +54,9 @@ export async function premisesCommand(options, io) {
53
54
  io.stderr.write('spec-harness: spec-guard could not run the briefs\' assertions\n');
54
55
  return EXIT_ERROR;
55
56
  }
56
- const document = answer.document;
57
- // A missing list is an empty one. A list that holds a string instead, the
58
- // mutant, sorts nothing to a brief either, since a string has no spec, so
59
- // it is equivalent; so is the one for errors.
60
- const results = document.results ?? [];
61
- // A directive spec-guard cannot read is listed apart from the results; one
62
- // in a premise section is a premise nothing checks.
63
- const errors = document.errors ?? [];
57
+ // A directive spec-guard cannot read is listed apart from the results, as
58
+ // errors; one in a premise section is a premise nothing checks.
59
+ const { results, errors } = readGuardRun(answer.document);
64
60
  // A directive is a brief's when spec-guard places it in the brief's file;
65
61
  // one it places nowhere is no brief's.
66
62
  const inBrief = (item, file) => item.spec?.file.replace(/\\/g, '/') === file;
@@ -86,7 +82,7 @@ export async function premisesCommand(options, io) {
86
82
  for (const error of unread) {
87
83
  const { line } = error.spec;
88
84
  if (premise(line))
89
- findings.push(unreadablePremiseFinding(brief, { message: error.message, line, raw: error.raw ?? '' }));
85
+ findings.push(unreadablePremiseFinding(brief, { message: error.message, line, raw: error.raw }));
90
86
  }
91
87
  }
92
88
  const stale = findings.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,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC;IAClC,CAAC;SAAM,CAAC;QACN,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAChH,CAAC;IACD,OAAO,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC;AACxC,CAAC","sourcesContent":["/**\n * `spec-harness premises`: is every live brief still about something true?\n *\n * A brief written against a defect states the defect as a premise - an\n * assertion under a section such as \"The Defect, Measured\" that holds while\n * the defect does. When the premise stops holding before the round has run,\n * the brief is stale: someone fixed the defect another way, or the code it\n * describes is gone. A repository that keeps its premises executable can say\n * so on every build, and ask for the brief to be archived or rewritten before\n * an agent is sent to fix what is already fixed.\n *\n * Goals are the audit's (`audit`), not this: a goal fails until its round is\n * done, and a build that failed for that would fail for every brief in flight.\n * For the same reason the premise of the brief a round is working on - the\n * one the flag, SPEC_BRIEF or the branch names - is reported as the audit\n * reports it, retired as the round intends, and fails nothing: on the round's\n * branch, a premise that no longer holds is the work being done.\n *\n * A premise spec-guard cannot read is checked by nothing, and is a warning,\n * as it is in the audit: `--strict` fails the run on it.\n */\n\nimport { isPremise, premiseFinding, unreadablePremiseFinding } from './audit.js';\nimport { briefIdFromBranch } from './branch.js';\nimport { findActive } from './briefs.js';\nimport { CONFIG_FILE } from './config.js';\nimport { formatFindings } from './formats.js';\nimport { createReader } from './reader.js';\nimport { briefText } from './round.js';\nimport type { Finding } from './types.js';\nimport { EXIT_ERROR, EXIT_FAILED, EXIT_OK, json, openWorkspace, version, type CliIO, type Options } from './workspace.js';\n\n/** Where spec-guard places a directive. */\ninterface Spec {\n readonly file: string;\n readonly line: number;\n}\n\ninterface GuardResult {\n readonly ok: boolean;\n readonly description: string;\n readonly message: string;\n readonly spec?: Spec;\n}\n\ninterface GuardError {\n readonly message: string;\n readonly raw?: string;\n readonly spec?: Spec;\n}\n\nexport async function premisesCommand(options: Options, io: CliIO): Promise<number> {\n const workspace = await openWorkspace(options, io);\n const reader = createReader();\n const briefs = await workspace.siblings.briefs();\n const live = briefs.filter((brief) => brief.phase === 'live');\n const fromBranch = workspace.branch === null ? null : briefIdFromBranch(workspace.config.branches, workspace.branch);\n const active = findActive(briefs, { flag: options.brief, environment: io.env['SPEC_BRIEF'], branch: fromBranch });\n const round = active.kind === 'found' ? active.brief.file : null;\n if (live.length === 0) {\n if (options.format === 'json') io.stdout.write(json('premises', { ok: true, checked: 0, findings: [] }));\n else if (options.format === 'pretty') io.stdout.write('no live brief\\n');\n else io.stdout.write(formatFindings(options.format, [], { file: CONFIG_FILE, version: version(), summary: 'no live brief' }));\n return EXIT_OK;\n }\n const answer = await workspace.siblings.json('spec-guard', [...live.map((brief) => brief.file), '--ignore-status', '--json']);\n if ('absent' in answer) {\n io.stderr.write(`spec-harness: premises cannot be checked: ${answer.absent}\\n`);\n return EXIT_ERROR;\n }\n if (answer.code === 2) {\n io.stderr.write('spec-harness: spec-guard could not run the briefs\\' assertions\\n');\n return EXIT_ERROR;\n }\n const document = answer.document as { results?: GuardResult[]; errors?: GuardError[] };\n // A missing list is an empty one. A list that holds a string instead, the\n // mutant, sorts nothing to a brief either, since a string has no spec, so\n // it is equivalent; so is the one for errors.\n const results = document.results ?? [];\n // A directive spec-guard cannot read is listed apart from the results; one\n // in a premise section is a premise nothing checks.\n const errors = document.errors ?? [];\n // A directive is a brief's when spec-guard places it in the brief's file;\n // one it places nowhere is no brief's.\n const inBrief = <T extends { readonly spec?: Spec }>(item: T, file: string): item is T & { readonly spec: Spec } =>\n item.spec?.file.replace(/\\\\/g, '/') === file;\n const findings: Finding[] = [];\n let premises = 0;\n for (const brief of live) {\n const own = results.filter((result) => inBrief(result, brief.file));\n const unread = errors.filter((error) => inBrief(error, brief.file));\n // Only saves reading a brief with nothing to judge: going on finds nothing, so that mutant is equivalent.\n if (own.length === 0 && unread.length === 0) continue;\n const text = await briefText(workspace, brief);\n const premise = (line: number): boolean => isPremise(reader.sectionsAt(text, line), workspace.config.assertions.premises);\n for (const result of own) {\n const { line } = result.spec;\n if (!premise(line)) continue;\n premises += 1;\n if (result.ok) continue;\n findings.push(premiseFinding(brief, { description: result.description, message: result.message, line }, brief.file === round));\n }\n for (const error of unread) {\n const { line } = error.spec;\n if (premise(line)) findings.push(unreadablePremiseFinding(brief, { message: error.message, line, raw: error.raw ?? '' }));\n }\n }\n const stale = findings.filter((finding) => finding.severity === 'error').length;\n const retired = findings.filter((finding) => finding.severity === 'note').length;\n const unreadable = findings.filter((finding) => finding.severity === 'warning').length;\n // Only the round on the active brief retires a premise, so with one retired\n // there is an active brief, and dropping the second test is equivalent.\n const intended = retired === 0 || active.kind !== 'found' ? '' : `, and ${retired} retired by the round on brief ${active.brief.id}, as it intends`;\n const unchecked = unreadable === 0 ? '' : `; ${unreadable} premise(s) spec-guard cannot read, so not checked`;\n const summary = `${premises} premise(s) in ${live.length} live brief(s), ${stale} no longer hold${intended}${unchecked}`;\n // As the audit does: a warning fails the run under --strict.\n const failed = stale > 0 || (options.strict && unreadable > 0);\n if (options.format === 'json') {\n io.stdout.write(json('premises', { ok: !failed, briefs: live.length, premises, unreadable, findings }));\n } else if (options.format === 'pretty') {\n for (const finding of findings) io.stdout.write(`${finding.severity.padEnd(8)} ${finding.file}:${finding.line} ${finding.message}\\n ${finding.hint}\\n`);\n io.stdout.write(`${summary}\\n`);\n } else {\n io.stdout.write(formatFindings(options.format, findings, { file: CONFIG_FILE, version: version(), summary }));\n }\n return failed ? EXIT_FAILED : EXIT_OK;\n}\n"]}
1
+ {"version":3,"file":"premises.js","sourceRoot":"","sources":["../src/premises.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,YAAY,EAAa,MAAM,cAAc,CAA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,CAAC;AACxC,CAAC","sourcesContent":["/**\n * `spec-harness premises`: is every live brief still about something true?\n *\n * A brief written against a defect states the defect as a premise - an\n * assertion under a section such as \"The Defect, Measured\" that holds while\n * the defect does. When the premise stops holding before the round has run,\n * the brief is stale: someone fixed the defect another way, or the code it\n * describes is gone. A repository that keeps its premises executable can say\n * so on every build, and ask for the brief to be archived or rewritten before\n * an agent is sent to fix what is already fixed.\n *\n * Goals are the audit's (`audit`), not this: a goal fails until its round is\n * done, and a build that failed for that would fail for every brief in flight.\n * For the same reason the premise of the brief a round is working on - the\n * one the flag, SPEC_BRIEF or the branch names - is reported as the audit\n * reports it, retired as the round intends, and fails nothing: on the round's\n * branch, a premise that no longer holds is the work being done.\n *\n * A premise spec-guard cannot read is checked by nothing, and is a warning,\n * as it is in the audit: `--strict` fails the run on it.\n */\n\nimport { readGuardRun, type Spec } from './answers.js';\nimport { isPremise, premiseFinding, unreadablePremiseFinding } from './audit.js';\nimport { briefIdFromBranch } from './branch.js';\nimport { findActive } from './briefs.js';\nimport { CONFIG_FILE } from './config.js';\nimport { formatFindings } from './formats.js';\nimport { createReader } from './reader.js';\nimport { briefText } from './round.js';\nimport type { Finding } from './types.js';\nimport { EXIT_ERROR, EXIT_FAILED, EXIT_OK, json, openWorkspace, version, type CliIO, type Options } from './workspace.js';\n\nexport async function premisesCommand(options: Options, io: CliIO): Promise<number> {\n const workspace = await openWorkspace(options, io);\n const reader = createReader();\n const briefs = await workspace.siblings.briefs();\n const live = briefs.filter((brief) => brief.phase === 'live');\n const fromBranch = briefIdFromBranch(workspace.config.branches, workspace.branch);\n const active = findActive(briefs, { flag: options.brief, environment: io.env['SPEC_BRIEF'], branch: fromBranch });\n const round = active.kind === 'found' ? active.brief.file : null;\n if (live.length === 0) {\n if (options.format === 'json') io.stdout.write(json('premises', { ok: true, checked: 0, findings: [] }));\n else if (options.format === 'pretty') io.stdout.write('no live brief\\n');\n else io.stdout.write(formatFindings(options.format, [], { file: CONFIG_FILE, version: version(), summary: 'no live brief' }));\n return EXIT_OK;\n }\n const answer = await workspace.siblings.json('spec-guard', [...live.map((brief) => brief.file), '--ignore-status', '--json']);\n if ('absent' in answer) {\n io.stderr.write(`spec-harness: premises cannot be checked: ${answer.absent}\\n`);\n return EXIT_ERROR;\n }\n if (answer.code === 2) {\n io.stderr.write('spec-harness: spec-guard could not run the briefs\\' assertions\\n');\n return EXIT_ERROR;\n }\n // A directive spec-guard cannot read is listed apart from the results, as\n // errors; one in a premise section is a premise nothing checks.\n const { results, errors } = readGuardRun(answer.document);\n // A directive is a brief's when spec-guard places it in the brief's file;\n // one it places nowhere is no brief's.\n const inBrief = <T extends { readonly spec?: Spec | undefined }>(item: T, file: string): item is T & { readonly spec: Spec } =>\n item.spec?.file.replace(/\\\\/g, '/') === file;\n const findings: Finding[] = [];\n let premises = 0;\n for (const brief of live) {\n const own = results.filter((result) => inBrief(result, brief.file));\n const unread = errors.filter((error) => inBrief(error, brief.file));\n // Only saves reading a brief with nothing to judge: going on finds nothing, so that mutant is equivalent.\n if (own.length === 0 && unread.length === 0) continue;\n const text = await briefText(workspace, brief);\n const premise = (line: number): boolean => isPremise(reader.sectionsAt(text, line), workspace.config.assertions.premises);\n for (const result of own) {\n const { line } = result.spec;\n if (!premise(line)) continue;\n premises += 1;\n if (result.ok) continue;\n findings.push(premiseFinding(brief, { description: result.description, message: result.message, line }, brief.file === round));\n }\n for (const error of unread) {\n const { line } = error.spec;\n if (premise(line)) findings.push(unreadablePremiseFinding(brief, { message: error.message, line, raw: error.raw }));\n }\n }\n const stale = findings.filter((finding) => finding.severity === 'error').length;\n const retired = findings.filter((finding) => finding.severity === 'note').length;\n const unreadable = findings.filter((finding) => finding.severity === 'warning').length;\n // Only the round on the active brief retires a premise, so with one retired\n // there is an active brief, and dropping the second test is equivalent.\n const intended = retired === 0 || active.kind !== 'found' ? '' : `, and ${retired} retired by the round on brief ${active.brief.id}, as it intends`;\n const unchecked = unreadable === 0 ? '' : `; ${unreadable} premise(s) spec-guard cannot read, so not checked`;\n const summary = `${premises} premise(s) in ${live.length} live brief(s), ${stale} no longer hold${intended}${unchecked}`;\n // As the audit does: a warning fails the run under --strict.\n const failed = stale > 0 || (options.strict && unreadable > 0);\n if (options.format === 'json') {\n io.stdout.write(json('premises', { ok: !failed, briefs: live.length, premises, unreadable, findings }));\n } else if (options.format === 'pretty') {\n for (const finding of findings) io.stdout.write(`${finding.severity.padEnd(8)} ${finding.file}:${finding.line} ${finding.message}\\n ${finding.hint}\\n`);\n io.stdout.write(`${summary}\\n`);\n } else {\n io.stdout.write(formatFindings(options.format, findings, { file: CONFIG_FILE, version: version(), summary }));\n }\n return failed ? EXIT_FAILED : EXIT_OK;\n}\n"]}
package/dist/round.d.ts CHANGED
@@ -40,7 +40,7 @@ export interface RulingCheck {
40
40
  * last changed its row must be signed by a principal the base branch's
41
41
  * allowed-signers file lists (ADR-0006).
42
42
  */
43
- export declare function checkRulings(workspace: Workspace, brief: BriefRow, text: string, reader: DocumentReader, base: Base): Promise<RulingCheck>;
43
+ export declare function checkRulings(workspace: Workspace, brief: Pick<BriefRow, 'file'>, text: string, reader: DocumentReader, base: Base): Promise<RulingCheck>;
44
44
  export declare function briefText(workspace: Workspace, brief: BriefRow): Promise<string>;
45
45
  /** Decides paths against the brief, with the rulings verified against the base `baseFlag` names, or the configured one. */
46
46
  export declare function checkPaths(workspace: Workspace, brief: BriefRow | null, noBrief: string | undefined, given: readonly string[], cwd: string, reader: DocumentReader, baseFlag: string | undefined): Promise<Decision[]>;
package/dist/round.js CHANGED
@@ -9,12 +9,14 @@ import { existsSync, readFileSync, realpathSync } from 'node:fs';
9
9
  import { readdir, readFile, rm } from 'node:fs/promises';
10
10
  import { join, resolve } from 'node:path';
11
11
  import { fileURLToPath } from 'node:url';
12
+ import { readArchivePlan, readGuardRun } from './answers.js';
12
13
  import { audit, tally } from './audit.js';
14
+ import { SiblingOutputError } from './briefs.js';
13
15
  import { sameId } from './branch.js';
14
16
  import { enabledPlugin, exportedFile, holdsGuard, loadsPlugin, registersServer, SPEC_BRIEF_CONFIGS, } from './configure.js';
15
17
  import { readRules, renderContext } from './context.js';
16
18
  import { readJsonObject, readText, repositoryPath, stateDirectory, writeAtomic } from './fs.js';
17
- import { blameLine, changes, mergeBase, remoteDefault, revision, show, verifyCommit } from './git.js';
19
+ import { blameLine, changes, isUncommitted, mergeBase, remoteDefault, revision, show, verifyCommit } from './git.js';
18
20
  import { decide } from './guard.js';
19
21
  import { diffManifest, ecosystemOf, readManifestNames } from './manifests.js';
20
22
  import { addRulingRow, nextId, readRulings, renderMemo, renderRow, } from './rulings.js';
@@ -30,9 +32,11 @@ export async function resolveBase(workspace, flag) {
30
32
  return { kind: 'unresolved', reason: 'no base is named and the remote has no default branch; pass --base <ref> or set "base"' };
31
33
  }
32
34
  const sha = await revision(ref, workspace.root);
33
- const head = await revision('HEAD', workspace.root);
34
- if (sha === null || head === null)
35
+ if (sha === null)
35
36
  return { kind: 'unresolved', reason: `"${ref}" names no commit` };
37
+ const head = await revision('HEAD', workspace.root);
38
+ if (head === null)
39
+ return { kind: 'unresolved', reason: 'HEAD names no commit: nothing is committed on this branch yet' };
36
40
  const common = await mergeBase(sha, head, workspace.root);
37
41
  if (common === null)
38
42
  return { kind: 'unresolved', reason: `"${ref}" and HEAD share no history` };
@@ -54,6 +58,8 @@ export async function checkRulings(workspace, brief, text, reader, base) {
54
58
  line: problem.line,
55
59
  }));
56
60
  const allows = rows.filter((row) => row.decision === 'allow');
61
+ // Nothing below verifies a row that allows nothing, so this saves a git
62
+ // show and is equivalent to its mutants.
57
63
  if (allows.length === 0)
58
64
  return { rows, verified: [], unverified: [], problems: findings };
59
65
  if (base.kind === 'unresolved') {
@@ -64,6 +70,8 @@ export async function checkRulings(workspace, brief, text, reader, base) {
64
70
  const reason = `${base.ref} has no ${workspace.config.rulings.allowedSigners}, so no signature can count`;
65
71
  return { rows, verified: [], unverified: allows.map((row) => ({ id: row.id, reason })), problems: findings };
66
72
  }
73
+ // Only verify-commit below reads this copy, so where it is kept, and under
74
+ // what name, is equivalent to its mutants.
67
75
  const directory = await stateDirectory(workspace.commonDir, 'signers');
68
76
  const file = join(directory, `${createHash('sha256').update(signers).digest('hex').slice(0, 16)}`);
69
77
  await writeAtomic(file, signers);
@@ -74,12 +82,12 @@ export async function checkRulings(workspace, brief, text, reader, base) {
74
82
  // HEAD the same number can be another line, one a signed commit wrote,
75
83
  // and an uncommitted row would borrow that commit's signature.
76
84
  const commit = await blameLine(null, brief.file, row.line, workspace.root);
77
- if (commit === null || /^0+$/.test(commit)) {
85
+ if (commit === null || isUncommitted(commit)) {
78
86
  unverified.push({ id: row.id, reason: 'its row is not committed' });
79
87
  continue;
80
88
  }
81
89
  const signature = await verifyCommit(commit, file, workspace.root);
82
- if (signature.good && signature.principal !== null)
90
+ if (signature.good)
83
91
  verified.push({ id: row.id, paths: row.paths, signer: signature.principal });
84
92
  else
85
93
  unverified.push({ id: row.id, reason: `commit ${commit.slice(0, 12)} last changed its row, and ${signature.detail || 'it is not signed'}` });
@@ -95,21 +103,18 @@ export async function briefText(workspace, brief) {
95
103
  }
96
104
  /** Decides paths against the brief, with the rulings verified against the base `baseFlag` names, or the configured one. */
97
105
  export async function checkPaths(workspace, brief, noBrief, given, cwd, reader, baseFlag) {
98
- let rulings = [];
99
106
  const resolved = given.map((path) => ({ given: path, path: repositoryPath(path, workspace.root, cwd) }));
100
- if (brief !== null) {
101
- // Rulings cost a blame and a signature check each, so they are read only
102
- // when a write reaches a protected file.
103
- const first = resolved.map(({ path, given: g }) => decide({ path, given: g, brief, noBrief, rulings: [], outOfScope: workspace.config.outOfScope }));
104
- if (first.some((decision) => decision.reason === 'protected')) {
105
- const base = await resolveBase(workspace, baseFlag);
106
- rulings = (await checkRulings(workspace, brief, await briefText(workspace, brief), reader, base)).verified;
107
- }
108
- else {
109
- return first;
110
- }
111
- }
112
- return resolved.map(({ path, given: g }) => decide({ path, given: g, brief, noBrief, rulings, outOfScope: workspace.config.outOfScope }));
107
+ const decideAll = (rulings) => resolved.map(({ path, given: g }) => decide({ path, given: g, brief, noBrief, rulings, outOfScope: workspace.config.outOfScope }));
108
+ const first = decideAll([]);
109
+ // Rulings cost a blame and a signature check each, so they are read only
110
+ // when a write reaches a protected file. Read anyway, they decide the same,
111
+ // since a ruling allows only a protected path, so mutants that always read
112
+ // them are equivalent; and with no brief nothing is protected, so the null
113
+ // check is there for the type.
114
+ if (brief === null || !first.some((decision) => decision.reason === 'protected'))
115
+ return first;
116
+ const base = await resolveBase(workspace, baseFlag);
117
+ return decideAll((await checkRulings(workspace, brief, await briefText(workspace, brief), reader, base)).verified);
113
118
  }
114
119
  /* ----------------------------------------------------------------- context */
115
120
  /**
@@ -160,9 +165,10 @@ async function rulesFor(workspace, brief) {
160
165
  return 'absent' in answer ? { unavailable: answer.absent } : readRules(answer);
161
166
  }
162
167
  catch (error) {
163
- // spec-guard printed no JSON: what it said instead is the reason, and
164
- // the rest of the packet stands without the rules.
165
- if (error instanceof SiblingError)
168
+ // spec-guard printed no JSON, or a document of another shape: what it
169
+ // said instead, or what was wrong, is the reason, and the rest of the
170
+ // packet stands without the rules.
171
+ if (error instanceof SiblingError || error instanceof SiblingOutputError)
166
172
  return { unavailable: error.message };
167
173
  throw error;
168
174
  }
@@ -181,7 +187,7 @@ async function citedDocuments(workspace, brief, text, reader) {
181
187
  // A destination that is not valid percent-encoding is read as written.
182
188
  }
183
189
  const path = resolveInside(dirname(brief.file), target);
184
- if (path === null || path === '' || path === brief.file || seen.has(path))
190
+ if (path === null || path === brief.file || seen.has(path))
185
191
  continue;
186
192
  seen.add(path);
187
193
  const document = /\.(?:md|markdown|mdx|txt)$/i.test(path);
@@ -190,6 +196,8 @@ async function citedDocuments(workspace, brief, text, reader) {
190
196
  if (!document && existsSync(join(workspace.root, path)))
191
197
  continue;
192
198
  const content = document ? await readText(join(workspace.root, path)) : null;
199
+ // A document that cannot be read is listed by its path alone, so its
200
+ // title and status are never read, and an empty object is equivalent.
193
201
  const meta = content === null ? { title: null, status: null } : reader.titleAndStatus(content);
194
202
  out.push({ path, ...meta, text: content });
195
203
  }
@@ -208,14 +216,9 @@ export async function buildContext(workspace, brief, briefs, reader, baseFlag) {
208
216
  briefText: text,
209
217
  dependencies: brief.dependsOn.map((id) =>
210
218
  // spec-brief reports a dependency as its front matter spells it, `7` for brief 007.
211
- briefs.find((candidate) => sameId(candidate.id, id)) ?? {
212
- ...brief,
213
- id,
214
- title: '(no such brief)',
215
- file: '',
216
- phase: 'live',
217
- status: 'unknown',
218
- }),
219
+ // The context reads a dependency's id, title, status and phase, and
220
+ // the brief copied here is live.
221
+ briefs.find((candidate) => sameId(candidate.id, id)) ?? { ...brief, id, title: '(no such brief)', status: 'unknown' }),
219
222
  cited,
220
223
  rules,
221
224
  rulings: rulings.verified,
@@ -242,8 +245,10 @@ async function dependencyChanges(workspace, base) {
242
245
  unread.push(change.path);
243
246
  continue;
244
247
  }
245
- const before = change.status === 'A' ? null : await show(base.mergeBase, change.from ?? change.path, workspace.root);
246
- const after = change.status === 'D' ? null : await show(base.head, change.path, workspace.root);
248
+ // git shows nothing where a file is not: an added manifest has no before,
249
+ // and a deleted one no after.
250
+ const before = await show(base.mergeBase, change.from ?? change.path, workspace.root);
251
+ const after = await show(base.head, change.path, workspace.root);
247
252
  const diff = diffManifest(change.path, ecosystem, before, after);
248
253
  if ('error' in diff)
249
254
  unread.push(change.path);
@@ -298,6 +303,8 @@ export async function specBriefPlugin(root) {
298
303
  if (file === undefined)
299
304
  return { kind: 'unconfigured' };
300
305
  const config = await readJsonObject(join(root, file));
306
+ // The file was found a moment ago, so null is one removed in between, and
307
+ // reads as the unreadable one it has become.
301
308
  if (config === null || config === 'unreadable')
302
309
  return { kind: 'unreadable', file };
303
310
  return { kind: loadsPlugin(config, pluginFile(root)) ? 'loaded' : 'not-loaded', file };
@@ -338,12 +345,13 @@ async function archiveReasons(workspace, brief, base) {
338
345
  if (base.kind === 'resolved')
339
346
  args.push('--base', base.ref);
340
347
  const answer = await workspace.siblings.json('spec-brief', args);
348
+ // The audit listed the briefs through spec-brief before it asks this, so
349
+ // an absent one stopped it there; the check is for the type.
341
350
  if ('absent' in answer)
342
351
  return { unavailable: answer.absent };
343
352
  if (answer.code === 2)
344
353
  return { unavailable: 'spec-brief could not plan the archive' };
345
- const plan = answer.document.plan;
346
- return { blocking: plan?.blocking ?? [], warnings: plan?.warnings ?? [] };
354
+ return readArchivePlan(answer.document);
347
355
  }
348
356
  /** The brief's assertions as spec-guard ran them, and those it could not read, which it lists apart as `errors`. */
349
357
  async function briefAssertions(workspace, brief, text, reader) {
@@ -352,15 +360,15 @@ async function briefAssertions(workspace, brief, text, reader) {
352
360
  return { unavailable: answer.absent };
353
361
  if (answer.code === 2)
354
362
  return { unavailable: 'spec-guard could not run the brief\'s assertions' };
355
- const report = answer.document;
363
+ const report = readGuardRun(answer.document);
356
364
  const own = (spec) => spec === undefined || spec.file.replace(/\\/g, '/') === brief.file;
357
- const outcomes = (report.results ?? [])
365
+ const outcomes = report.results
358
366
  .filter((result) => own(result.spec))
359
367
  .map((result) => {
360
368
  const line = result.spec?.line ?? 0;
361
369
  return { ok: result.ok, description: result.description, message: result.message, line, section: reader.sectionAt(text, line), enclosing: reader.sectionsAt(text, line) };
362
370
  });
363
- const unreadable = (report.errors ?? []).filter((error) => own(error.spec)).map((error) => ({ message: error.message, line: error.spec?.line ?? 0, raw: error.raw ?? '' }));
371
+ const unreadable = report.errors.filter((error) => own(error.spec)).map((error) => ({ message: error.message, line: error.spec?.line ?? 0, raw: error.raw }));
364
372
  return { outcomes, unreadable };
365
373
  }
366
374
  export async function runAudit(workspace, brief, reader, baseFlag) {
@@ -440,6 +448,8 @@ export async function recordRuling(workspace, escalationId, decision, note, read
440
448
  const id = nextId('R', request.brief, taken);
441
449
  const row = renderRow(id, request.paths, decision, note);
442
450
  await writeAtomic(path, addRulingRow(text, workspace.config.rulings.section, row, where));
451
+ // Listed a moment ago; forced, a request another process retired in
452
+ // between is not an error, so the option is equivalent to its mutants.
443
453
  await rm(join(await escalationDirectory(workspace), `${request.id}.json`), { force: true });
444
454
  return { id, file: request.briefFile, row };
445
455
  }