Skip to content

fix(view): reject anchors absent from knowledge/index.json - #192

Open
titanwings wants to merge 1 commit into
atomic/pr-1-unique-anchorsfrom
atomic/pr-2-view-back-refs
Open

titanwings wants to merge 1 commit into
atomic/pr-1-unique-anchorsfrom
atomic/pr-2-view-back-refs

Conversation

@titanwings

Copy link
Copy Markdown
Owner

Why

画像页可以引用账本里不存在的锚点。view check 只核对 evidence[],doctor 用方括号正则扫 view.json,JSON 里的 "anchors": ["k9999"] 扫不到。SKILL.md Step 5.1 要求先 view check 再渲染,这条回指当时是空的。

数据形状如下。

输入 调用 字面期望
合法 view.json,其中一条 anchors 改成 k9999,并补进 evidence[] view check --json 退出 1,diagnostics[0].code 为 view/orphan-anchor
同上 view render --json 退出 1,views/ 下没有 html,也没有 receipt
同一工作区 doctor --json 退出 1,anchors.dangling 为 1
孤立 --file,旁边没有 knowledge/index.json view check --file --json 退出 0,warnings 含 VIEW_LEDGER_ABSENT

Scope

view check 与 view render 在有 --person 或 --base-dir 时读 knowledge/index.json。每个 anchors[] 元素在账本锚点集合里查成员,缺失则发 view/orphan-anchor error 并退出 1。

--file 模式没有账本时打一条 warning VIEW_LEDGER_ABSENT,不静默。

view render 复用同一校验,有 error 时不写 html 也不写 receipt。renderView 内部的 checkView 也会从 view 文件旁的账本再读一次。

doctor 的 deliveredAnchors 对 .view.json 走 JSON.parse,收集每个 anchors[],覆盖 headline.anchors、sections[].claims[].anchors、sections[].items[].anchors、points[].anchors。其余文件仍走方括号正则。不改 corpusShape。

删掉 audit-tests 基线里这两行。

  • R49 doctor fails when views/.view.json cites an anchor the ledger does not declare
  • R38 SKILL.md Step 5.1: view check rejects an anchor that does not exist in knowledge/index.json

这两行对应 tests/audit 里的 T47 与 T60。基线数据行从 19 减到 17。

Blast Radius

已有合法画像不受影响。R36 在 harvest 后的真实账本上 view check 仍退出 0,diagnostics 为空。

只变严悬空引用。栈停在 dot-skill-test,dot-skill 保留。

Verification

T47、T60 由红转绿。基线从 19 行减到 17 行。

改前,Node v22.14.0,HEAD 319e8c3:

PASS audit-tests  (5.3s, exit 1)
     ratchet failing 19, baseline 19

改后,Node v22.14.0,HEAD 8784cac:

PASS audit-tests  (5.1s, exit 1)
     ratchet failing 17, baseline 17

改后,Node v20.20.2:

PASS audit-tests  (7.2s, exit 1)
     ratchet failing 17, baseline 17

node scripts/run-gates.mjs --without playwright 在 Node v20.20.2 与 Node v22.14.0 都是 8/8 gates passed。npm test 是 # tests 403、# fail 0。

DISTILLY_PLAYWRIGHT_ROOT=/tmp/pw-root node scripts/run-gates.mjs --requires playwright 在 Node v22.14.0 上是 3/3 gates passed。三份语料都是 验收结果:18/18 通过。us-house 含 FAIL · units=2744 speakers=18 attributed=85。

You see,Node v22.14.0。工作区 harvest synthetic-interview 后写入引用 k9999 的 view.json。

  • view check --json 退出 1,diagnostics[0].code 为 view/orphan-anchor
  • view render --json 退出 1,views/ 下没有 html
  • doctor --json 退出 1,anchors.dangling 为 1

新用例在 base 上失败,在 head 上通过。base 是 Node v22.14.0。

a cited id missing from the ledger is view/orphan-anchor 失败:

Expected values to be strictly equal:

true !== false

cli: view check --json exits 1 with view/orphan-anchor when the ledger lacks the cited id 失败:

Expected values to be strictly equal:

0 !== 1

cli: view render exits 1 and writes no html when a cited anchor is absent from the ledger 失败:

Expected values to be strictly equal:

0 !== 1

cli: view check --file without a ledger warns VIEW_LEDGER_ABSENT and still exits 0 失败:

{"warnings":[],"codes":[]}

false !== true

doctor fails when views/<slug>.view.json cites an anchor the ledger does not declare 失败:

a view.json citation the ledger does not declare must fail doctor

0 !== 1

head 上 node --test tests/views.test.mjs tests/doctor-coverage.test.mjs 是 # tests 43、# fail 0。

Rollback

回退 8784cac。已渲染的 html 不用迁移。栈停在 dot-skill-test,dot-skill 保留。

view check and view render fail with view/orphan-anchor when a cited id
is missing from the ledger. doctor JSON-parses view.json anchors[].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants