proofdeck 0.0.0-stage → 0.1.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/LICENSE +201 -0
- package/NOTICE +23 -0
- package/README.md +97 -2
- package/README.zh-CN.md +89 -0
- package/bin/proofdeck.js +126 -0
- package/board/LICENSE +201 -0
- package/board/README.md +473 -0
- package/board/README.zh-CN.md +424 -0
- package/board/dist/_chk.db-shm +0 -0
- package/board/dist/_chk.db-wal +0 -0
- package/board/dist/adapters.d.ts +40 -0
- package/board/dist/adapters.d.ts.map +1 -0
- package/board/dist/adapters.js +124 -0
- package/board/dist/adapters.js.map +1 -0
- package/board/dist/board.d.ts +628 -0
- package/board/dist/board.d.ts.map +1 -0
- package/board/dist/board.js +2767 -0
- package/board/dist/board.js.map +1 -0
- package/board/dist/cli.d.ts +3 -0
- package/board/dist/cli.d.ts.map +1 -0
- package/board/dist/cli.js +1663 -0
- package/board/dist/cli.js.map +1 -0
- package/board/dist/config.d.ts +57 -0
- package/board/dist/config.d.ts.map +1 -0
- package/board/dist/config.js +99 -0
- package/board/dist/config.js.map +1 -0
- package/board/dist/db.d.ts +9 -0
- package/board/dist/db.d.ts.map +1 -0
- package/board/dist/db.js +506 -0
- package/board/dist/db.js.map +1 -0
- package/board/dist/git.d.ts +35 -0
- package/board/dist/git.d.ts.map +1 -0
- package/board/dist/git.js +147 -0
- package/board/dist/git.js.map +1 -0
- package/board/dist/index.d.ts +18 -0
- package/board/dist/index.d.ts.map +1 -0
- package/board/dist/index.js +13 -0
- package/board/dist/index.js.map +1 -0
- package/board/dist/mcp-config.d.ts +26 -0
- package/board/dist/mcp-config.d.ts.map +1 -0
- package/board/dist/mcp-config.js +88 -0
- package/board/dist/mcp-config.js.map +1 -0
- package/board/dist/mcp.d.ts +3 -0
- package/board/dist/mcp.d.ts.map +1 -0
- package/board/dist/mcp.js +949 -0
- package/board/dist/mcp.js.map +1 -0
- package/board/dist/quickstart.d.ts +75 -0
- package/board/dist/quickstart.d.ts.map +1 -0
- package/board/dist/quickstart.js +156 -0
- package/board/dist/quickstart.js.map +1 -0
- package/board/dist/serve.d.ts +10 -0
- package/board/dist/serve.d.ts.map +1 -0
- package/board/dist/serve.js +445 -0
- package/board/dist/serve.js.map +1 -0
- package/board/dist/signing.d.ts +18 -0
- package/board/dist/signing.d.ts.map +1 -0
- package/board/dist/signing.js +26 -0
- package/board/dist/signing.js.map +1 -0
- package/board/dist/sync.d.ts +49 -0
- package/board/dist/sync.d.ts.map +1 -0
- package/board/dist/sync.js +158 -0
- package/board/dist/sync.js.map +1 -0
- package/board/dist/types.d.ts +359 -0
- package/board/dist/types.d.ts.map +1 -0
- package/board/dist/types.js +20 -0
- package/board/dist/types.js.map +1 -0
- package/board/docs/adr/0001-shared-worktree-collision.md +102 -0
- package/board/docs/adr/0001-shared-worktree-collision.zh-CN.md +90 -0
- package/board/docs/attribution.md +123 -0
- package/board/docs/attribution.zh-CN.md +104 -0
- package/board/docs/development-workflow.md +81 -0
- package/board/docs/development-workflow.zh-CN.md +75 -0
- package/board/docs/diagrams/banner.png +0 -0
- package/board/docs/diagrams/banner.svg +1 -0
- package/board/docs/diagrams/before-after.png +0 -0
- package/board/docs/diagrams/before-after.svg +1 -0
- package/board/docs/diagrams/governance-chain.png +0 -0
- package/board/docs/diagrams/governance-chain.svg +1 -0
- package/board/docs/diagrams/value-flow.png +0 -0
- package/board/docs/diagrams/value-flow.svg +1 -0
- package/board/docs/entry-point.md +81 -0
- package/board/docs/entry-point.zh-CN.md +65 -0
- package/board/docs/kanban.png +0 -0
- package/board/docs/octoryn-mark.png +0 -0
- package/board/docs/registry-metadata.md +34 -0
- package/board/docs/registry-metadata.zh-CN.md +30 -0
- package/board/package.json +87 -0
- package/config.example.json +71 -0
- package/daemon.js +1112 -0
- package/docs/assets/demo.gif +0 -0
- package/docs/demo-run.mjs +61 -0
- package/docs/render-demo.py +94 -0
- package/e2e/verify-acceptance.mjs +150 -0
- package/e2e/verify-antifraud.mjs +128 -0
- package/e2e/verify-caps.mjs +46 -0
- package/e2e/verify-checkpoint.mjs +208 -0
- package/e2e/verify-firstclass.mjs +110 -0
- package/e2e/verify-judge.mjs +52 -0
- package/e2e/verify-lease.mjs +95 -0
- package/e2e/verify-replay.mjs +92 -0
- package/e2e/verify-resilience.mjs +323 -0
- package/e2e/verify-review.mjs +86 -0
- package/e2e/verify-scheduling.mjs +110 -0
- package/e2e/verify-schema-evolution.mjs +107 -0
- package/e2e/verify-sla-digest.mjs +105 -0
- package/guard.js +97 -0
- package/lib/adapters/codex.js +206 -0
- package/lib/billing-convert.js +57 -0
- package/lib/board.js +46 -0
- package/lib/caps.js +35 -0
- package/lib/checkpoint.js +130 -0
- package/lib/gating.js +218 -0
- package/lib/guard-core.mjs +108 -0
- package/lib/http.js +161 -0
- package/lib/judge.js +89 -0
- package/lib/lease.js +93 -0
- package/lib/notify.js +56 -0
- package/lib/platform.js +120 -0
- package/lib/replay.js +68 -0
- package/lib/review.js +40 -0
- package/lib/runner.js +152 -0
- package/lib/schedule.js +59 -0
- package/lib/sla.js +42 -0
- package/lib/spans.js +36 -0
- package/lib/starve.js +43 -0
- package/lib/store.js +109 -0
- package/lib/supply.js +101 -0
- package/lib/usage.js +103 -0
- package/lib/verify.js +223 -0
- package/lib/watchdog-core.mjs +68 -0
- package/lib/watchdog-worker.mjs +75 -0
- package/package.json +55 -4
- package/scripts/run-daemon.sh +18 -0
- package/scripts/run-e2e.mjs +39 -0
|
Binary file
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Demo: a "fake done" gets caught by the real verification engine.
|
|
2
|
+
// This is NOT a mock — it calls lib/verify.js evaluateAcceptance with the same
|
|
3
|
+
// fail-closed check types the daemon runs before accepting a done claim.
|
|
4
|
+
//
|
|
5
|
+
// Output is a plain-text terminal transcript (no ANSI), so render-demo.mjs can
|
|
6
|
+
// turn an actual run into the demo GIF honestly.
|
|
7
|
+
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
|
+
import { join, dirname } from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
import { pathToFileURL } from "node:url";
|
|
12
|
+
|
|
13
|
+
const root = dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
const { evaluateAcceptance } = await import(pathToFileURL(join(root, "..", "lib", "verify.js")).href);
|
|
15
|
+
|
|
16
|
+
const work = mkdtempSync(join(tmpdir(), "proofdeck-demo-"));
|
|
17
|
+
const line = (s) => console.log(s);
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
// The agent "finished" the task and wrote its report — but only 1 item, not 3.
|
|
21
|
+
mkdirSync(join(work, "out"), { recursive: true });
|
|
22
|
+
writeFileSync(join(work, "out", "report.json"), JSON.stringify({ count: 1, note: "everything done!" }));
|
|
23
|
+
|
|
24
|
+
line("$ proofdeck task claim fix-pagination # agent starts working");
|
|
25
|
+
line("$ ... agent edits files, runs tests, writes out/report.json");
|
|
26
|
+
line("$ proofdeck task done fix-pagination # agent claims DONE");
|
|
27
|
+
line("");
|
|
28
|
+
|
|
29
|
+
const acceptance = {
|
|
30
|
+
baseDir: work,
|
|
31
|
+
checks: [
|
|
32
|
+
{ type: "countAtLeast", path: "out/report.json", jsonPath: "count", min: 3 },
|
|
33
|
+
{ type: "fileExists", path: "out/notes.md" },
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
line(" acceptance gate — fail-closed:");
|
|
38
|
+
for (const c of acceptance.checks) line(` · ${c.type} ${c.path}${c.jsonPath ? " ." + c.jsonPath : ""}${c.min != null ? " >= " + c.min : ""}`);
|
|
39
|
+
line("");
|
|
40
|
+
line(" verify V1 running...");
|
|
41
|
+
|
|
42
|
+
const v = evaluateAcceptance({ acceptance });
|
|
43
|
+
for (const r of v.checks) {
|
|
44
|
+
line(` ${r.pass ? "PASS" : "FAIL"} ${r.type} ${r.target ?? ""} ${r.evidence ?? ""}`);
|
|
45
|
+
}
|
|
46
|
+
line("");
|
|
47
|
+
|
|
48
|
+
if (!v.pass) {
|
|
49
|
+
line(" done REJECTED — no evidence, no completion.");
|
|
50
|
+
line(" => task returns to open for redispatch (retry/breaker applies).");
|
|
51
|
+
line(" => a verify event is appended to the sha256 hash chain.");
|
|
52
|
+
line(" => upstream UI shows: \"agent said done; ProofDeck demanded proof.\"");
|
|
53
|
+
line("");
|
|
54
|
+
line(` demo workspace: ${work}`);
|
|
55
|
+
} else {
|
|
56
|
+
line(" PASS — done accepted (this demo expects FAIL; something changed!)");
|
|
57
|
+
}
|
|
58
|
+
} finally {
|
|
59
|
+
// Keep the demo output stable; workspace is a throwaway — delete it.
|
|
60
|
+
try { rmSync(work, { recursive: true, force: true }); } catch { }
|
|
61
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Render demo-transcript.txt (an ACTUAL run of docs/demo-run.mjs) into demo.gif.
|
|
3
|
+
|
|
4
|
+
Honesty: every line comes verbatim from a real invocation of lib/verify.js —
|
|
5
|
+
this script only styles the text; it never invents output.
|
|
6
|
+
"""
|
|
7
|
+
from PIL import Image, ImageDraw, ImageFont
|
|
8
|
+
import sys, os
|
|
9
|
+
|
|
10
|
+
TRANSCRIPT = "D:/AgentHub/tmp/demo-transcript.txt"
|
|
11
|
+
OUT = os.path.join(os.path.dirname(__file__), "assets", "demo.gif")
|
|
12
|
+
|
|
13
|
+
W, H = 1000, 620
|
|
14
|
+
PAD = 28
|
|
15
|
+
LINE_H = 25
|
|
16
|
+
BG = (16, 26, 27)
|
|
17
|
+
BAR = (25, 37, 40)
|
|
18
|
+
INK = (237, 240, 223)
|
|
19
|
+
DIM = (140, 158, 152)
|
|
20
|
+
MINT = (166, 208, 185)
|
|
21
|
+
RED = (255, 107, 107)
|
|
22
|
+
GOLD = (233, 199, 121)
|
|
23
|
+
ORANGE = (255, 159, 67)
|
|
24
|
+
|
|
25
|
+
def font(size=16, prefer=("C:/Windows/Fonts/consola.ttf", "C:/Windows/Fonts/cour.ttf", "C:/Windows/Fonts/msyh.ttc")):
|
|
26
|
+
for f in prefer:
|
|
27
|
+
if os.path.exists(f):
|
|
28
|
+
return ImageFont.truetype(f, size)
|
|
29
|
+
return ImageFont.load_default()
|
|
30
|
+
|
|
31
|
+
f_body = font(16)
|
|
32
|
+
f_cjk = font(15, ("C:/Windows/Fonts/msyh.ttc",)) # engine evidence strings are Chinese
|
|
33
|
+
f_bar = font(13)
|
|
34
|
+
f_foot = font(12)
|
|
35
|
+
|
|
36
|
+
lines = open(TRANSCRIPT, encoding="utf-8").read().splitlines()
|
|
37
|
+
# Strip volatile temp paths to keep the demo readable and stable.
|
|
38
|
+
lines = [l.replace("D:\\OPENCO~1\\", "D:\\tmp\\").replace("D:\\AgentHub\\tmp\\", "D:\\tmp\\") for l in lines]
|
|
39
|
+
|
|
40
|
+
def color_of(text: str):
|
|
41
|
+
t = text.strip()
|
|
42
|
+
if t.startswith("$"):
|
|
43
|
+
return MINT
|
|
44
|
+
if "FAIL" in t:
|
|
45
|
+
return RED
|
|
46
|
+
if "REJECTED" in t:
|
|
47
|
+
return ORANGE
|
|
48
|
+
if t.startswith("acceptance gate"):
|
|
49
|
+
return GOLD
|
|
50
|
+
if t.startswith("·") or t.startswith("verify V1"):
|
|
51
|
+
return DIM
|
|
52
|
+
if t.startswith("=>"):
|
|
53
|
+
return DIM
|
|
54
|
+
return INK
|
|
55
|
+
|
|
56
|
+
def frame(shown: int, final: bool) -> Image.Image:
|
|
57
|
+
im = Image.new("RGB", (W, H), BG)
|
|
58
|
+
d = ImageDraw.Draw(im)
|
|
59
|
+
# Title bar
|
|
60
|
+
d.rectangle([0, 0, W, 38], fill=BAR)
|
|
61
|
+
d.ellipse([16, 13, 26, 23], fill=(255, 95, 86))
|
|
62
|
+
d.ellipse([32, 13, 42, 23], fill=(255, 189, 46))
|
|
63
|
+
d.ellipse([48, 13, 58, 23], fill=(39, 201, 63))
|
|
64
|
+
d.text((72, 11), "proofdeck — acceptance gate (actual run of lib/verify.js)", font=f_bar, fill=DIM)
|
|
65
|
+
y = 62
|
|
66
|
+
for i in range(0, shown):
|
|
67
|
+
col = color_of(lines[i])
|
|
68
|
+
use = f_cjk if any(ord(ch) > 127 for ch in lines[i]) else f_body
|
|
69
|
+
d.text((PAD, y), lines[i], font=use, fill=col)
|
|
70
|
+
y += LINE_H
|
|
71
|
+
if final:
|
|
72
|
+
# highlight the REJECTED block
|
|
73
|
+
for i, l in enumerate(lines):
|
|
74
|
+
if "done REJECTED" in l:
|
|
75
|
+
yy = 62 + i * LINE_H - 4
|
|
76
|
+
d.rectangle([PAD - 10, yy, W - PAD, yy + LINE_H * 3 + 6], outline=RED, width=2)
|
|
77
|
+
d.text((PAD, H - 22), "text rendered from a real invocation — no fabricated output", font=f_foot, fill=DIM)
|
|
78
|
+
return im
|
|
79
|
+
|
|
80
|
+
frames = []
|
|
81
|
+
durations = []
|
|
82
|
+
# Progressive reveal: a few lines per frame for the fast part, slower at the verdict.
|
|
83
|
+
for shown in range(1, len(lines) + 1):
|
|
84
|
+
is_verdict = any("REJECTED" in lines[i] for i in range(max(0, shown - 3), shown))
|
|
85
|
+
frames.append(frame(shown, final=(shown == len(lines))))
|
|
86
|
+
durations.append(120 if not is_verdict else 420)
|
|
87
|
+
# Hold the last frame
|
|
88
|
+
for _ in range(4):
|
|
89
|
+
frames.append(frame(len(lines), final=True))
|
|
90
|
+
durations.append(900)
|
|
91
|
+
|
|
92
|
+
os.makedirs(os.path.dirname(OUT), exist_ok=True)
|
|
93
|
+
frames[0].save(OUT, save_all=True, append_images=frames[1:], duration=durations, loop=0, optimize=False)
|
|
94
|
+
print(f"wrote {OUT} ({len(frames)} frames, {sum(durations)/1000:.1f}s)")
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// e2e: acceptance verification V1 (验证层 Part B) — pure checks + full fail-path
|
|
2
|
+
// integration against a TEST board and a temp store. Never touches the real board.
|
|
3
|
+
import { mkdtempSync, writeFileSync, mkdirSync, readFileSync, rmSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { pathToFileURL, fileURLToPath } from "node:url";
|
|
7
|
+
|
|
8
|
+
const V = await import(new URL("../lib/verify.js", import.meta.url).href);
|
|
9
|
+
const { Store } = await import(new URL("../lib/store.js", import.meta.url).href);
|
|
10
|
+
const boardCh = await import(new URL("../lib/board.js", import.meta.url).href);
|
|
11
|
+
|
|
12
|
+
let pass = 0, fail = 0;
|
|
13
|
+
const ok = (name, cond, detail = "") => {
|
|
14
|
+
if (cond) { pass++; console.log(`PASS ${name}${detail ? " — " + detail : ""}`); }
|
|
15
|
+
else { fail++; console.log(`FAIL ${name}${detail ? " — " + detail : ""}`); }
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const dir = mkdtempSync(join(tmpdir(), "bridge-verify-"));
|
|
19
|
+
const boardDir = join(dir, "board");
|
|
20
|
+
const storeDir = mkdtempSync(join(tmpdir(), "bridge-vstore-"));
|
|
21
|
+
const store = new Store(join(storeDir, "state.json"));
|
|
22
|
+
await boardCh.init(fileURLToPath(new URL("../board", import.meta.url)));
|
|
23
|
+
const cfg = { dir: boardDir, identity: "bridge" };
|
|
24
|
+
|
|
25
|
+
// ---------- P1: parseBridgeBlock ----------
|
|
26
|
+
{
|
|
27
|
+
const d1 = '正文\n```bridge\n{ "priority": "P1", "retry": {"max": 1}, "acceptance": { "checks": [] } }\n```\n尾部';
|
|
28
|
+
const b1 = V.parseBridgeBlock(d1);
|
|
29
|
+
ok("P1a valid block parsed", b1?.priority === "P1" && b1?.retry?.max === 1);
|
|
30
|
+
ok("P1b no block → null", V.parseBridgeBlock("没有围栏") === null && V.parseBridgeBlock(null) === null);
|
|
31
|
+
ok("P1c malformed JSON → null", V.parseBridgeBlock("```bridge\n{oops}\n```") === null);
|
|
32
|
+
ok("P1d array payload → null", V.parseBridgeBlock("```bridge\n[1,2]\n```") === null);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ---------- P2: evaluateAcceptance ----------
|
|
36
|
+
{
|
|
37
|
+
const root = join(dir, "work");
|
|
38
|
+
mkdirSync(root, { recursive: true });
|
|
39
|
+
writeFileSync(join(root, "out.md"), "## 第1首\n内容\n## 第2首\n内容\n");
|
|
40
|
+
writeFileSync(join(root, "ledger.json"), JSON.stringify({ items: [{ a: 1 }, { a: 2 }, { a: 3 }], total: 7 }));
|
|
41
|
+
writeFileSync(join(root, "empty.txt"), "");
|
|
42
|
+
|
|
43
|
+
ok("P2a null acceptance → null", V.evaluateAcceptance({ acceptance: null }) === null);
|
|
44
|
+
ok("P2b empty checks → null", V.evaluateAcceptance({ acceptance: { checks: [] } }) === null);
|
|
45
|
+
ok("P2c mode human → null (V3 待建)", V.evaluateAcceptance({ acceptance: { mode: "human", checks: [{ type: "fileExists", path: "out.md" }] } }) === null);
|
|
46
|
+
|
|
47
|
+
const allPass = V.evaluateAcceptance({
|
|
48
|
+
acceptance: { baseDir: root, checks: [
|
|
49
|
+
{ type: "fileExists", path: "out.md" },
|
|
50
|
+
{ type: "countAtLeast", path: "ledger.json", jsonPath: "$.items", min: 3 },
|
|
51
|
+
{ type: "countAtLeast", path: "ledger.json", jsonPath: "$.total", min: 7 },
|
|
52
|
+
{ type: "countOccurrences", path: "out.md", text: "## 第", minCount: 2 },
|
|
53
|
+
] },
|
|
54
|
+
});
|
|
55
|
+
ok("P2d all-pass aggregate", allPass?.pass === true && allPass.checks.length === 4, JSON.stringify(allPass?.checks?.map(c => c.pass)));
|
|
56
|
+
|
|
57
|
+
const short = V.evaluateAcceptance({
|
|
58
|
+
acceptance: { baseDir: root, checks: [
|
|
59
|
+
{ type: "countAtLeast", path: "ledger.json", jsonPath: "$.items", min: 20 },
|
|
60
|
+
{ type: "fileExists", path: "missing.md" },
|
|
61
|
+
{ type: "countOccurrences", path: "out.md", text: "## 第", minCount: 9 },
|
|
62
|
+
] },
|
|
63
|
+
});
|
|
64
|
+
ok("P2e work-level fails detected", short?.pass === false && short.checks.filter((c) => !c.pass).length === 3 && short.checks.every((c) => c.invalid !== true),
|
|
65
|
+
JSON.stringify(short.checks.filter(c => !c.pass).map(c => c.evidence)));
|
|
66
|
+
|
|
67
|
+
const invalid = V.evaluateAcceptance({
|
|
68
|
+
acceptance: { baseDir: root, checks: [
|
|
69
|
+
{ type: "fileExsits", path: "out.md" },
|
|
70
|
+
{ type: "countOccurrences", path: "out.md" },
|
|
71
|
+
{ type: "countAtLeast", path: "ledger.json", jsonPath: "$.nope.deep", min: 1 },
|
|
72
|
+
] },
|
|
73
|
+
});
|
|
74
|
+
ok("P2f spec errors flagged invalid, path-miss is work-level",
|
|
75
|
+
invalid?.pass === false && invalid.checks[0].invalid === true && invalid.checks[1].invalid === true && invalid.checks[2].invalid !== true,
|
|
76
|
+
JSON.stringify(invalid.checks.map(c => ({ p: c.pass, inv: !!c.invalid }))));
|
|
77
|
+
|
|
78
|
+
ok("P2g empty file fails fileExists (minBytes default 1)",
|
|
79
|
+
V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [{ type: "fileExists", path: "empty.txt" }] } }).pass === false);
|
|
80
|
+
ok("P2h absolute path works", V.evaluateAcceptance({ acceptance: { checks: [{ type: "fileExists", path: join(root, "out.md").replaceAll("\\", "/") }] } }).pass === true);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// ---------- P3: full fail-path integration on a TEST board ----------
|
|
84
|
+
{
|
|
85
|
+
await boardCh.withBoard(cfg, (b) => {
|
|
86
|
+
b.defineTask("zcode", "e2e-verify-1", { title: "verify e2e", description: "测试任务" });
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const v = { pass: false, checks: [
|
|
90
|
+
{ type: "countAtLeast", target: "out.md $.items", pass: false, evidence: "got 12 < 20" },
|
|
91
|
+
{ type: "fileExists", target: "missing.md", pass: false, evidence: "不存在" },
|
|
92
|
+
] };
|
|
93
|
+
|
|
94
|
+
// 第一次:未用尽 → retry-scheduled + 回 open + note/message
|
|
95
|
+
let res;
|
|
96
|
+
await boardCh.withBoard(cfg, (b) => {
|
|
97
|
+
res = V.applyVerifyFail({ b, io: boardCh, store, ID: "bridge", owner: "kemu", key: "e2e-verify-1", agent: "trae", task: { createdBy: "zcode" }, v, maxAttempts: 2, baseMs: 60000, maxDelayMs: 240000, holdBase: 300000, holdMax: 7200000, now: Date.now() });
|
|
98
|
+
});
|
|
99
|
+
ok("P3a first verify-fail schedules retry", res.outcome === "retry-scheduled" && res.attempts === 1, JSON.stringify(res));
|
|
100
|
+
ok("P3b retries ledger written", store.s.retries["e2e-verify-1"]?.n === 1 && store.s.retries["e2e-verify-1"]?.why === "verify-fail");
|
|
101
|
+
await boardCh.withBoard(cfg, (b) => {
|
|
102
|
+
const t = b.getTask("e2e-verify-1");
|
|
103
|
+
ok("P3c task back to open", t?.status === "open", t?.status);
|
|
104
|
+
const evs = b.timeline(200);
|
|
105
|
+
const note = evs.filter((e) => e.kind === "note" && String(e.summary).includes("[[verify]]")).pop();
|
|
106
|
+
ok("P3d structured verify FAIL note on chain", !!note && String(note.summary).includes("verdict=FAIL") && String(note.summary).includes("checks=0/2"), String(note?.summary).slice(0, 80));
|
|
107
|
+
const msgs = b.inbox("zcode", true);
|
|
108
|
+
ok("P3e creator notified", msgs.some((m) => (m.body ?? "").includes("未通过验收") || JSON.stringify(m).includes("未通过验收")));
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// 第二、三次:attempts 递增到用尽 → blocked + verification 熔断
|
|
112
|
+
await boardCh.withBoard(cfg, (b) => {
|
|
113
|
+
res = V.applyVerifyFail({ b, io: boardCh, store, ID: "bridge", owner: "kemu", key: "e2e-verify-1", agent: "trae", task: { createdBy: "zcode" }, v, maxAttempts: 2, baseMs: 60000, maxDelayMs: 240000, holdBase: 300000, holdMax: 7200000, now: Date.now() });
|
|
114
|
+
});
|
|
115
|
+
ok("P3f-pre second retry scheduled (max=2 → 还允许最后一试)", res.outcome === "retry-scheduled" && res.attempts === 2, JSON.stringify(res));
|
|
116
|
+
await boardCh.withBoard(cfg, (b) => {
|
|
117
|
+
res = V.applyVerifyFail({ b, io: boardCh, store, ID: "bridge", owner: "kemu", key: "e2e-verify-1", agent: "trae", task: { createdBy: "zcode" }, v, maxAttempts: 2, baseMs: 60000, maxDelayMs: 240000, holdBase: 300000, holdMax: 7200000, now: Date.now() });
|
|
118
|
+
});
|
|
119
|
+
ok("P3f exhaustion → blocked + face latched", res.outcome === "exhausted" && res.streak === 1, JSON.stringify(res));
|
|
120
|
+
ok("P3g verification latch recorded", store.supplyGet("trae")?.category === "verification");
|
|
121
|
+
ok("P3h retries ledger cleared", store.s.retries["e2e-verify-1"] === undefined);
|
|
122
|
+
await boardCh.withBoard(cfg, (b) => {
|
|
123
|
+
ok("P3i task blocked", b.getTask("e2e-verify-1")?.status === "blocked");
|
|
124
|
+
ok("P3j chain intact", b.verifyChain().brokenAtSeq === null);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// PASS 路径
|
|
128
|
+
const vp = { pass: true, checks: [{ type: "fileExists", target: "out.md", pass: true, evidence: "12B" }] };
|
|
129
|
+
await boardCh.withBoard(cfg, (b) => V.applyVerifyPass({ b, io: boardCh, ID: "bridge", key: "e2e-verify-1", v: vp }));
|
|
130
|
+
await boardCh.withBoard(cfg, (b) => {
|
|
131
|
+
const evs = b.timeline(300);
|
|
132
|
+
const note = evs.filter((e) => e.kind === "note" && String(e.summary).includes("[[verify]]")).pop();
|
|
133
|
+
ok("P3k structured PASS note", !!note && String(note.summary).includes("verdict=PASS") && String(note.summary).includes("checks=1/1"));
|
|
134
|
+
ok("P3l chain still intact", b.verifyChain().brokenAtSeq === null);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// ---------- P4: formatVerifyNote ----------
|
|
139
|
+
{
|
|
140
|
+
const n = V.formatVerifyNote({ key: "k1", verdict: "FAIL", checks: [
|
|
141
|
+
{ type: "fileExists", target: "a.md", pass: false, evidence: "不存在" },
|
|
142
|
+
{ type: "fileExists", target: "b.md", pass: true, evidence: "1B" },
|
|
143
|
+
], by: "bridge" });
|
|
144
|
+
ok("P4a note format stable", n.startsWith("[[verify]] key=k1 verdict=FAIL level=V1 by=bridge checks=1/2") && n.includes("· FAIL fileExists a.md"), n.slice(0, 100));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
rmSync(dir, { recursive: true, force: true });
|
|
148
|
+
rmSync(storeDir, { recursive: true, force: true });
|
|
149
|
+
console.log(`\n${pass} PASS, ${fail} FAIL`);
|
|
150
|
+
process.exit(fail ? 1 : 0);
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// e2e: 防刷分检查(2026-10-07)—— countMatches / referencesExist 两类组合一致性检查。
|
|
2
|
+
// SpecBench 教训:声明式检查可被针对性刷穿;组合检查迫使刷单必须整条链一起伪造。
|
|
3
|
+
// 纯检查测试 + 一次 board 集成,不碰现网。
|
|
4
|
+
import { mkdtempSync, writeFileSync, mkdirSync, rmSync } from "node:fs";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { pathToFileURL } from "node:url";
|
|
8
|
+
|
|
9
|
+
const V = await import(new URL("../lib/verify.js", import.meta.url).href);
|
|
10
|
+
|
|
11
|
+
let pass = 0, fail = 0;
|
|
12
|
+
const ok = (name, cond, detail = "") => {
|
|
13
|
+
if (cond) { pass++; console.log(`PASS ${name}${detail ? " — " + detail : ""}`); }
|
|
14
|
+
else { fail++; console.log(`FAIL ${name}${detail ? " — " + detail : ""}`); }
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const dir = mkdtempSync(join(tmpdir(), "bridge-antifraud-"));
|
|
18
|
+
const root = join(dir, "work");
|
|
19
|
+
mkdirSync(join(root, "out"), { recursive: true });
|
|
20
|
+
mkdirSync(join(root, "assets"), { recursive: true });
|
|
21
|
+
|
|
22
|
+
// 工件:产物 + 台账 + 引用资源
|
|
23
|
+
writeFileSync(join(root, "out", "ledger.json"), JSON.stringify({ items: [{ id: 1 }, { id: 2 }, { id: 3 }], rendered: 3 }));
|
|
24
|
+
writeFileSync(join(root, "out", "manifest.json"), JSON.stringify({ count: 3 }));
|
|
25
|
+
writeFileSync(join(root, "out", "refs.json"), JSON.stringify({ files: ["assets/a.png", "assets/b.png"] }));
|
|
26
|
+
writeFileSync(join(root, "out", "badrefs.json"), JSON.stringify({ files: ["assets/a.png", "assets/ghost.png"] }));
|
|
27
|
+
writeFileSync(join(root, "out", "norefs.json"), JSON.stringify({ files: [] }));
|
|
28
|
+
writeFileSync(join(root, "assets", "a.png"), "fake-image-a");
|
|
29
|
+
writeFileSync(join(root, "assets", "b.png"), "fake-image-b");
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
// ---- countMatches ----
|
|
33
|
+
{
|
|
34
|
+
const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
|
|
35
|
+
{ type: "countMatches", path: "out/ledger.json", jsonPath: "$.items", withPath: "out/manifest.json", withJsonPath: "$.count", min: 3 },
|
|
36
|
+
] } });
|
|
37
|
+
ok("M1a 数量一致且达标 → PASS", r?.pass === true, JSON.stringify(r?.checks?.[0]));
|
|
38
|
+
}
|
|
39
|
+
{
|
|
40
|
+
const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
|
|
41
|
+
{ type: "countMatches", path: "out/ledger.json", jsonPath: "$.items", withPath: "out/manifest.json", withJsonPath: "$.count" },
|
|
42
|
+
] } });
|
|
43
|
+
ok("M1b 一致但缺 min(默认1)此处 3≥1 → PASS", r?.pass === true);
|
|
44
|
+
}
|
|
45
|
+
{
|
|
46
|
+
const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
|
|
47
|
+
{ type: "countMatches", path: "out/ledger.json", jsonPath: "$.items", withPath: "out/ledger.json", withJsonPath: "$.rendered", min: 3 },
|
|
48
|
+
] } });
|
|
49
|
+
// items=3 vs rendered=3 → 相等 → pass(同文件自比也合法)
|
|
50
|
+
ok("M1c 同文件两路径相等 → PASS", r?.pass === true);
|
|
51
|
+
}
|
|
52
|
+
{
|
|
53
|
+
// 刷分模拟:产物说 3,台账只给了 2 —— 不一致必须 FAIL
|
|
54
|
+
writeFileSync(join(root, "out", "liar.json"), JSON.stringify({ count: 2 }));
|
|
55
|
+
const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
|
|
56
|
+
{ type: "countMatches", path: "out/ledger.json", jsonPath: "$.items", withPath: "out/liar.json", withJsonPath: "$.count", min: 3 },
|
|
57
|
+
] } });
|
|
58
|
+
ok("M2a 数量不一致 → FAIL(work 类)", r?.pass === false && r.checks[0].invalid !== true, r?.checks?.[0]?.evidence);
|
|
59
|
+
}
|
|
60
|
+
{
|
|
61
|
+
const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
|
|
62
|
+
{ type: "countMatches", path: "out/ledger.json", jsonPath: "$.nonexistent", withPath: "out/manifest.json", withJsonPath: "$.count" },
|
|
63
|
+
] } });
|
|
64
|
+
ok("M2b 路径未命中 → FAIL(work 类,取值不可计数)", r?.pass === false && r.checks[0].invalid !== true);
|
|
65
|
+
}
|
|
66
|
+
{
|
|
67
|
+
const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
|
|
68
|
+
{ type: "countMatches", path: "out/ledger.json", withPath: "out/manifest.json" },
|
|
69
|
+
] } });
|
|
70
|
+
ok("M3a 缺 jsonPath → spec 类 invalid", r?.pass === false && r.checks[0].invalid === true);
|
|
71
|
+
}
|
|
72
|
+
{
|
|
73
|
+
// 相等但为 0:没有 min 时默认 1,防"两边都是空的也算过"
|
|
74
|
+
writeFileSync(join(root, "out", "zero.json"), JSON.stringify({ a: 0 }));
|
|
75
|
+
const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
|
|
76
|
+
{ type: "countMatches", path: "out/zero.json", jsonPath: "$.a", withPath: "out/zero.json", withJsonPath: "$.a" },
|
|
77
|
+
] } });
|
|
78
|
+
ok("M3b 相等但为 0 → FAIL(默认 min 1)", r?.pass === false, r?.checks?.[0]?.evidence);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ---- referencesExist ----
|
|
82
|
+
{
|
|
83
|
+
const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
|
|
84
|
+
{ type: "referencesExist", path: "out/refs.json", jsonPath: "$.files" },
|
|
85
|
+
] } });
|
|
86
|
+
ok("R1a 引用全部存在 → PASS", r?.pass === true, JSON.stringify(r?.checks?.[0]?.evidence));
|
|
87
|
+
}
|
|
88
|
+
{
|
|
89
|
+
const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
|
|
90
|
+
{ type: "referencesExist", path: "out/badrefs.json", jsonPath: "$.files" },
|
|
91
|
+
] } });
|
|
92
|
+
ok("R2a 幽灵引用 → FAIL(work 类,证据点名缺失项)", r?.pass === false && String(r.checks[0].evidence).includes("ghost.png"), r?.checks?.[0]?.evidence);
|
|
93
|
+
}
|
|
94
|
+
{
|
|
95
|
+
const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
|
|
96
|
+
{ type: "referencesExist", path: "out/norefs.json", jsonPath: "$.files" },
|
|
97
|
+
] } });
|
|
98
|
+
ok("R2b 引用列表为空 → FAIL(fail-closed)", r?.pass === false && r.checks[0].invalid !== true);
|
|
99
|
+
}
|
|
100
|
+
{
|
|
101
|
+
const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
|
|
102
|
+
{ type: "referencesExist", path: "out/refs.json", jsonPath: "$.files", baseDir: root },
|
|
103
|
+
] } });
|
|
104
|
+
ok("R3a 显式 baseDir 相对解析 → PASS", r?.pass === true);
|
|
105
|
+
}
|
|
106
|
+
{
|
|
107
|
+
const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
|
|
108
|
+
{ type: "referencesExist", path: "out/refs.json" },
|
|
109
|
+
] } });
|
|
110
|
+
ok("R3b 缺 jsonPath → spec 类 invalid", r?.pass === false && r.checks[0].invalid === true);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// ---- 混合:防刷分检查与三类既有检查同场 ----
|
|
114
|
+
{
|
|
115
|
+
const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
|
|
116
|
+
{ type: "fileExists", path: "out/ledger.json" },
|
|
117
|
+
{ type: "countAtLeast", path: "out/ledger.json", jsonPath: "$.items", min: 3 },
|
|
118
|
+
{ type: "countMatches", path: "out/ledger.json", jsonPath: "$.items", withPath: "out/manifest.json", withJsonPath: "$.count" },
|
|
119
|
+
{ type: "referencesExist", path: "out/refs.json", jsonPath: "$.files" },
|
|
120
|
+
] } });
|
|
121
|
+
ok("X1 四类检查同场全过 → aggregate PASS", r?.pass === true && r.checks.length === 4);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
console.log(`\n${pass} passed, ${fail} failed`);
|
|
125
|
+
if (fail > 0) process.exit(1);
|
|
126
|
+
} finally {
|
|
127
|
+
try { rmSync(dir, { recursive: true, force: true }); } catch { }
|
|
128
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// e2e: 能力匹配(采纳建议③ 第一步)—— parseNeeds / faceHasCaps / pickCapableFace。
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
|
|
4
|
+
const C = await import(new URL("../lib/caps.js", import.meta.url).href);
|
|
5
|
+
|
|
6
|
+
let pass = 0, fail = 0;
|
|
7
|
+
const ok = (name, cond, detail = "") => {
|
|
8
|
+
if (cond) { pass++; console.log(`PASS ${name}${detail ? " — " + detail : ""}`); }
|
|
9
|
+
else { fail++; console.log(`FAIL ${name}${detail ? " — " + detail : ""}`); }
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// ---- parseNeeds ----
|
|
13
|
+
ok("N1 数组归一化", JSON.stringify(C.parseNeeds({ needs: ["Content", " coding "] })) === JSON.stringify(["content", "coding"]));
|
|
14
|
+
ok("N2 单字符串", JSON.stringify(C.parseNeeds({ needs: "Content" })) === JSON.stringify(["content"]));
|
|
15
|
+
ok("N3 缺失/空 → []", JSON.stringify(C.parseNeeds({})) === "[]" && JSON.stringify(C.parseNeeds({ needs: [] })) === "[]" && JSON.stringify(C.parseNeeds(null)) === "[]");
|
|
16
|
+
ok("N4 过滤垃圾项", JSON.stringify(C.parseNeeds({ needs: ["a", "", 3, null] })) === JSON.stringify(["a", "3"]));
|
|
17
|
+
|
|
18
|
+
// ---- faceHasCaps(向后兼容语义)----
|
|
19
|
+
ok("C1 任务无 needs → 万能", C.faceHasCaps([], []) === true && C.faceHasCaps(undefined, []) === true);
|
|
20
|
+
ok("C2 面未声明能力 → 万能(存量配置零改动)", C.faceHasCaps(undefined, ["content"]) === true && C.faceHasCaps([], ["content"]) === true);
|
|
21
|
+
ok("C3 双边声明 → 子集才合格", C.faceHasCaps(["content", "coding"], ["content"]) === true);
|
|
22
|
+
ok("C4 缺能力 → 不合格", C.faceHasCaps(["coding"], ["content", "coding"]) === false);
|
|
23
|
+
ok("C5 大小写不敏感", C.faceHasCaps(["Content"], ["content"]) === true);
|
|
24
|
+
|
|
25
|
+
// ---- pickCapableFace ----
|
|
26
|
+
{
|
|
27
|
+
const cfgA = { f1: { capabilities: ["coding"] }, f2: { capabilities: ["content", "coding"] }, f3: {} };
|
|
28
|
+
const reach = new Set(["f1", "f2", "f3"]);
|
|
29
|
+
const r1 = await C.pickCapableFace({
|
|
30
|
+
candidates: ["f1", "f2", "f3"], needs: ["content"], agentsCfg: cfgA,
|
|
31
|
+
isReachable: async (f) => reach.has(f),
|
|
32
|
+
});
|
|
33
|
+
ok("P1 缺能力的候选被跳过,选到有能力的", r1.face === "f2" && JSON.stringify(r1.skipped) === JSON.stringify(["f1"]), JSON.stringify(r1));
|
|
34
|
+
const r2 = await C.pickCapableFace({
|
|
35
|
+
candidates: ["f1", "f2"], needs: ["content"], agentsCfg: cfgA,
|
|
36
|
+
isReachable: async (f) => f !== "f2", // f2 有能力但探不通
|
|
37
|
+
});
|
|
38
|
+
ok("P2 有能力但探不通 → 继续找(无 → null)", r2.face === null && JSON.stringify(r2.skipped) === JSON.stringify(["f1", "f2"]), JSON.stringify(r2));
|
|
39
|
+
const r3 = await C.pickCapableFace({
|
|
40
|
+
candidates: ["f3"], needs: ["whatever"], agentsCfg: cfgA, isReachable: async () => true,
|
|
41
|
+
});
|
|
42
|
+
ok("P3 未声明能力的面视为万能", r3.face === "f3");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
console.log(`\n${pass} passed, ${fail} failed`);
|
|
46
|
+
if (fail > 0) process.exit(1);
|