dsh-vibe-math 2.3.0 → 2.3.2
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/AUDIT-CHECKLIST.md +78 -3
- package/README.md +33 -2
- package/RELEASE-NOTES-2.3.1.md +134 -0
- package/RELEASE-NOTES-2.3.2.md +145 -0
- package/audit-formal-sensitivity.mjs +134 -39
- package/audit-prompt-invariants.mjs +414 -0
- package/audit-spec-traceability.mjs +173 -0
- package/audit-v5-integrity.mjs +5 -3
- package/docs/formal-verification.md +122 -19
- package/docs/generate_framework_diagram_v5.mjs +2 -1
- package/docs/test-timing.md +101 -0
- package/formal-verify-v2.test.mjs +526 -7
- package/formal-verify-v3.test.mjs +389 -10
- package/formal-verify-v4.test.mjs +462 -4
- package/formal-verify-v5.test.mjs +163 -4
- package/installer.js +3 -1
- package/package.json +12 -2
- package/prompt-corpus-persona/persona-corpus.json +2 -2
- package/prompt-corpus-persona/persona-corpus.md +6 -2
- package/prompt-corpus-v2/formal-verify-v2.json +484 -0
- package/prompt-corpus-v2/formal-verify-v2.md +5239 -0
- package/prompt-corpus-v3/formal-verify-v3.json +274 -100
- package/prompt-corpus-v3/formal-verify-v3.md +2057 -335
- package/prompt-corpus-v4/formal-verify-v4.json +89 -0
- package/prompt-corpus-v4/formal-verify-v4.md +283 -0
- package/prompt-corpus-v5/prompt-corpus-v5.json +186 -219
- package/prompt-corpus-v5/prompt-corpus-v5.md +485 -700
- package/prompt-v5-integrity.test.mjs +1272 -1085
- package/run-tests.mjs +118 -0
- package/vibe-math-v2/vibe-math-v2.js +341 -45
- package/vibe-math-v2//345/256/236/347/216/260/346/226/271/346/241/210.md +129 -8
- package/vibe-math-v3/vibe-math-v3.js +162 -36
- package/vibe-math-v3//345/256/236/347/216/260/346/226/271/346/241/210.md +21 -3
- package/vibe-math-v4/vibe-math-v4.js +201 -30
- package/vibe-math-v4//345/256/236/347/216/260/346/226/271/346/241/210.md +54 -2
- package/vibe-math-v5/agent.cordis.yml +6 -2
- package/vibe-math-v5/vibe-math-v5.js +133 -28
- package/vibe-math-v5//345/256/236/347/216/260/346/226/271/346/241/210.md +55 -5
- package/vibe-math-v5//346/236/266/346/236/204/345/233/276.md +16 -2
- package//347/244/272/344/276/213/345/233/276//346/241/206/346/236/266/345/233/276-v5.svg +6 -5
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
//
|
|
26
26
|
// Run: node formal-verify-v4.test.mjs
|
|
27
27
|
// ============================================================
|
|
28
|
-
import { mkdtempSync, existsSync, readFileSync, mkdirSync, writeFileSync, readdirSync } from 'node:fs'
|
|
28
|
+
import { mkdtempSync, existsSync, readFileSync, mkdirSync, writeFileSync, readdirSync, rmSync } from 'node:fs'
|
|
29
29
|
import { tmpdir } from 'node:os'
|
|
30
|
-
import { join, dirname, isAbsolute } from 'node:path'
|
|
30
|
+
import { join, dirname, isAbsolute, resolve as pathResolve } from 'node:path'
|
|
31
31
|
import { pathToFileURL, fileURLToPath } from 'node:url'
|
|
32
32
|
|
|
33
33
|
// V4_PLUGIN (same convention the v5 suite uses for V5_PLUGIN): point the suite at a MUTATED copy of
|
|
@@ -41,6 +41,11 @@ function pluginUrl() {
|
|
|
41
41
|
return pathToFileURL(fileURLToPath(new URL('file:///' + s.replace(/\\/g, '/'))))
|
|
42
42
|
}
|
|
43
43
|
const PLUGIN = pluginUrl()
|
|
44
|
+
// docs §10 item 10: the Lean prompt corpus is shipped under prompt-corpus-v4/ so a HUMAN can read
|
|
45
|
+
// the exact text the framework sends. V4_CORPUS_DIR overrides the destination (same convention v3
|
|
46
|
+
// and v5 use for V3_CORPUS_DIR / V5_CORPUS_DIR).
|
|
47
|
+
const HERE = dirname(fileURLToPath(import.meta.url))
|
|
48
|
+
const CORPUS_DIR = process.env.V4_CORPUS_DIR ? pathResolve(process.env.V4_CORPUS_DIR) : join(HERE, 'prompt-corpus-v4')
|
|
44
49
|
|
|
45
50
|
let passed = 0, failed = 0
|
|
46
51
|
const failures = []
|
|
@@ -55,7 +60,17 @@ const readIf = (p) => (existsSync(p) ? readFileSync(p, 'utf8') : '')
|
|
|
55
60
|
// MOCK HOST — the shape selfdrive-v4 / e2e-v4-fixes use, plus a fake Lean
|
|
56
61
|
// ===============================================================
|
|
57
62
|
let toolchainAvailable = true
|
|
63
|
+
// A host that exposes NO `subprocess` service at all (docs §7 → NO_SUBPROCESS, and §6 hard rule 4
|
|
64
|
+
// requires the injected guidance to name that code so the resident records a blocker instead of
|
|
65
|
+
// retrying forever).
|
|
66
|
+
let subprocessAvailable = true
|
|
67
|
+
// A stub host whose shell EXITS 0 WITHOUT deleting anything (a permissions quirk / a stub host).
|
|
68
|
+
// Used by §13 to prove the withdrawal is not a best-effort delete: the framework must confirm the
|
|
69
|
+
// file is gone through the fs service and fall back to overwriting it with a withdrawal notice.
|
|
70
|
+
let shellDeletesFiles = true
|
|
58
71
|
const leanRuns = [] // every spawn the framework made, for cwd/argv assertions
|
|
72
|
+
const terminated = [] // files whose handle the framework actively terminate()d (docs §7)
|
|
73
|
+
const shellCalls = [] // every platform-shell script (mkdir at mount, Remove-Item on defect)
|
|
59
74
|
|
|
60
75
|
function makeSubprocess() {
|
|
61
76
|
return {
|
|
@@ -65,6 +80,24 @@ function makeSubprocess() {
|
|
|
65
80
|
return String(cmd)
|
|
66
81
|
},
|
|
67
82
|
spawn(spec) {
|
|
83
|
+
// The preset drives the platform shell through this SAME `subprocess` service (runShell:
|
|
84
|
+
// powershell / /bin/sh) for mkdir at mount, and — since docs §4.1 — for Remove-Item when a
|
|
85
|
+
// `defect` retracts an archived proof. Handle it here so that retraction is a REAL filesystem
|
|
86
|
+
// deletion, exactly as the real host performs it; otherwise "the proof file is gone" could
|
|
87
|
+
// only be asserted against a mock's bookkeeping.
|
|
88
|
+
const argv0 = String((spec.argv && spec.argv[0]) || '')
|
|
89
|
+
if (/powershell|cmd\.exe|\/bin\/sh|(^|\/)sh$/i.test(argv0)) {
|
|
90
|
+
const script = String(spec.argv[spec.argv.length - 1] || '')
|
|
91
|
+
shellCalls.push(script)
|
|
92
|
+
const m = script.match(/-LiteralPath\s+'((?:[^']|'')*)'/)
|
|
93
|
+
if (shellDeletesFiles && /Remove-Item/.test(script) && m) rmSync(m[1].replace(/''/g, "'"), { force: true })
|
|
94
|
+
if (shellDeletesFiles && /^rm -f /.test(script)) for (const q of script.slice(6).match(/'[^']*'/g) || []) rmSync(q.slice(1, -1), { force: true })
|
|
95
|
+
return {
|
|
96
|
+
done: Promise.resolve({ exitCode: 0, signal: null }),
|
|
97
|
+
collected: { stdout: { readFrom: () => ({ text: '', nextOffset: 0, lossy: false }) }, stderr: { readFrom: () => ({ text: '', nextOffset: 0, lossy: false }) } },
|
|
98
|
+
terminate() {},
|
|
99
|
+
}
|
|
100
|
+
}
|
|
68
101
|
// The plugin passes an ABSOLUTE path as the last argv element, so resolve it directly; fall
|
|
69
102
|
// back to scanning the argv for an existing .lean file (mirrors leanAbsPath).
|
|
70
103
|
const last = spec.argv[spec.argv.length - 1]
|
|
@@ -72,6 +105,16 @@ function makeSubprocess() {
|
|
|
72
105
|
const text = existsSync(file) ? readFileSync(file, 'utf8') : ''
|
|
73
106
|
const bad = /sorry|-- FAIL/.test(text)
|
|
74
107
|
leanRuns.push({ argv: spec.argv.slice(), file, cwd: spec.cwd, graceMs: spec.graceMs, stdio: spec.stdio })
|
|
108
|
+
// A HANG file never settles and never exits: the ONLY thing that can end it is the framework's
|
|
109
|
+
// own timeout calling handle.terminate() (docs §7). Records each terminate so the suite can
|
|
110
|
+
// assert the timeout path is ACTIVE, not merely reported.
|
|
111
|
+
if (/-- HANG/.test(text)) {
|
|
112
|
+
return {
|
|
113
|
+
done: new Promise(() => {}),
|
|
114
|
+
collected: { stdout: { readFrom: () => ({ text: '', nextOffset: 0, lossy: false }) }, stderr: { readFrom: () => ({ text: '', nextOffset: 0, lossy: false }) } },
|
|
115
|
+
terminate() { terminated.push(file) },
|
|
116
|
+
}
|
|
117
|
+
}
|
|
75
118
|
const stdout = bad ? '' : 'ok\n'
|
|
76
119
|
const stderr = bad ? 'error: declaration uses sorry\n' : ''
|
|
77
120
|
return {
|
|
@@ -92,7 +135,7 @@ function makeHost() {
|
|
|
92
135
|
const subprocess = makeSubprocess()
|
|
93
136
|
let ROOT
|
|
94
137
|
const ctx = {
|
|
95
|
-
get(name) { return name === 'subprocess' ? subprocess : undefined },
|
|
138
|
+
get(name) { return name === 'subprocess' && subprocessAvailable ? subprocess : undefined },
|
|
96
139
|
on(e, fn) { (listeners[e] = listeners[e] || []).push(fn) },
|
|
97
140
|
effect(fn) { const d = fn(); return () => { if (typeof d === 'function') d() } },
|
|
98
141
|
logger: { info() {}, warn() {}, error() {} },
|
|
@@ -249,6 +292,9 @@ const A = await establish()
|
|
|
249
292
|
assert(!/Lean/.test(all), 'no founding/round prompt mentions Lean in off mode')
|
|
250
293
|
assert(!/顺手形式化|Lean 通过|忠实性审查|vibe_v4_lean/.test(all), 'no founding/round prompt carries any Lean-formalization text in off mode')
|
|
251
294
|
assert(all.length > 0, 'sanity: the scan actually saw the founding prompts')
|
|
295
|
+
// `off` must not CREATE Lean state at all: the feature's durable record file must not appear
|
|
296
|
+
// for a session that never used the feature (v3's suite pins the same invariant).
|
|
297
|
+
assert(!existsSync(join(A.projectRoot, 'State', 'formal.json')), '★ off mode creates NO State/formal.json (a TRUE no-op, not just an empty record store)')
|
|
252
298
|
}
|
|
253
299
|
// an off-mode verification must behave exactly as before: unanimous 真 → Verified/, no formal record
|
|
254
300
|
const offSettled = await proposeAndVote(A, 'p-off', {
|
|
@@ -265,6 +311,39 @@ assert(!/顺手形式化/.test(await A.prompts('normal', 'r-1')), 'the work prom
|
|
|
265
311
|
assert(['vibe_v4_lean_run', 'vibe_v4_lean_archive', 'vibe_v4_lean_lib'].every(n => !!A.toolRegs.find(t => t.name === n)),
|
|
266
312
|
'the three Lean tools are registered in every mode (registration is static)')
|
|
267
313
|
|
|
314
|
+
// ★ The mode switch must be REACHABLE THROUGH THE TOOL SCHEMA (2.3.2 defect D1) ──────────────
|
|
315
|
+
// Every tool schema here is closed (`additionalProperties:false`), so a key the schema does not
|
|
316
|
+
// advertise is REJECTED by any schema-validating provider. v3 shipped 2.3.0/2.3.1 with all four Lean
|
|
317
|
+
// parameters missing from the set-params schema while every assertion in this file stayed green —
|
|
318
|
+
// because the suite calls the handler DIRECTLY and never inspects the registered schema. The feature
|
|
319
|
+
// could not be switched on at all through the tool interface.
|
|
320
|
+
{
|
|
321
|
+
const setSpec = A.toolRegs.find((t) => t.name === 'vibe_v4_set')
|
|
322
|
+
assert(!!setSpec, "vibe_v4_set is registered")
|
|
323
|
+
assert(setSpec.parameters && setSpec.parameters.type === 'object' && setSpec.parameters.additionalProperties === false,
|
|
324
|
+
'★ vibe_v4_set publishes a CLOSED object schema (an unlisted key is rejected, so the schema IS the contract)')
|
|
325
|
+
for (const k of ['formalVerify', 'leanCommand', 'leanArgs', 'leanTimeoutMs']) {
|
|
326
|
+
assert(Object.prototype.hasOwnProperty.call(setSpec.parameters.properties, k),
|
|
327
|
+
'★ the registered schema advertises ' + k + ' (every other surface documents it; a schema that omits it makes the switch unreachable)')
|
|
328
|
+
}
|
|
329
|
+
assert(JSON.stringify(setSpec.parameters.properties.formalVerify.enum) === JSON.stringify(['off', 'encourage', 'require']),
|
|
330
|
+
'the schema narrows formalVerify to the three real modes (a typo must not be a fourth)')
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// A stray `formal` reply in OFF mode must be INERT (finding #1): the reply contract does not offer
|
|
334
|
+
// the field there, so honouring it would contradict "off is a TRUE no-op". The TOOLS stay usable.
|
|
335
|
+
{
|
|
336
|
+
await A.callTool('vibe_v4_record_proposition', { id: 'p-offreply', title: 'off', statement: '关模式下注入回执', prob: 0.8, value: 0.6, motivation: 'm' }, A.resAgent(A.childOf('r-1')))
|
|
337
|
+
const wOffR = await workWake(A, 'r-1')
|
|
338
|
+
A.fireEnd(wOffR.childId, { summary: '继续。', solved: false, contextPct: 20, formal: { target: 'p-offreply', decision: 'defect', note: '不应被记录' } })
|
|
339
|
+
await sleep(80)
|
|
340
|
+
const stOffReply = await A.callTool('vibe_v4_status', {})
|
|
341
|
+
assert(stOffReply.formal.objects.length === 0, '★ a stray `formal` reply in off mode records NO formal object')
|
|
342
|
+
assert(!existsSync(join(A.projectRoot, 'Formal', 'p-offreply.lean')), '★ and writes no formal working file')
|
|
343
|
+
assert(!existsSync(join(A.projectRoot, 'Formal', 'TODO.md')) || !/p-offreply/.test(readIf(join(A.projectRoot, 'Formal', 'TODO.md'))), '★ and creates no TODO entry')
|
|
344
|
+
assert(!existsSync(join(A.projectRoot, 'State', 'formal.json')), '★ and still no State/formal.json after the stray reply (the off-mode guard is a true no-op)')
|
|
345
|
+
}
|
|
346
|
+
|
|
268
347
|
// ---------- 2. parameter validation + runtime switching ----------
|
|
269
348
|
section('2 parameter validation and runtime switching')
|
|
270
349
|
const B = await establish()
|
|
@@ -377,6 +456,31 @@ assert(noTc.ok === false && noTc.code === 'LEAN_NOT_FOUND', '★ a missing toolc
|
|
|
377
456
|
assert(/仍可把形式化代码写下来归档/.test(noTc.message || ''), 'the failure explains the graceful degradation')
|
|
378
457
|
assert((await D.callTool('vibe_v4_status', {})).ok === true, 'the group did NOT crash on the missing toolchain (status still answers)')
|
|
379
458
|
toolchainAvailable = true
|
|
459
|
+
// No `subprocess` service at all (docs §7): the run must degrade to a typed NO_SUBPROCESS result —
|
|
460
|
+
// never a thrown error into the scheduler — and an object it was asked to record must stay
|
|
461
|
+
// `attempted` (an un-runnable host must not mint a `passed` record).
|
|
462
|
+
{
|
|
463
|
+
subprocessAvailable = false
|
|
464
|
+
const noSub = await D.callTool('vibe_v4_lean_run', { file: 'Formal/good.lean', target: 'p-nosub' }, r1)
|
|
465
|
+
assert(noSub.ok === false && noSub.code === 'NO_SUBPROCESS', '★ a host with no subprocess service returns NO_SUBPROCESS instead of crashing (got ' + noSub.code + ')')
|
|
466
|
+
assert(/no subprocess service/.test(String(noSub.message || '')), 'the failure is readable (it explains that Lean cannot be executed here)')
|
|
467
|
+
const stNoSub = await D.callTool('vibe_v4_status', {})
|
|
468
|
+
assert(stNoSub.ok === true, 'the group did NOT crash on the missing service (status still answers)')
|
|
469
|
+
const recNoSub = stNoSub.formal.objects.find((o) => o.target === 'p-nosub')
|
|
470
|
+
assert(recNoSub && recNoSub.status === 'attempted' && !recNoSub.proof, '★ the object record stays honest: attempted (never passed) when nothing could be executed')
|
|
471
|
+
subprocessAvailable = true
|
|
472
|
+
}
|
|
473
|
+
// A run that never finishes: the framework must ACTIVELY terminate it (docs §7) and still report a
|
|
474
|
+
// readable LEAN_TIMEOUT — relying on the host's own graceMs alone leaves the Lean process running.
|
|
475
|
+
{
|
|
476
|
+
writeFileSync(join(D.projectRoot, 'Formal', 'hang.lean'), '-- HANG\ntheorem t : 1 = 1 := rfl\n', 'utf8')
|
|
477
|
+
const t0 = Date.now()
|
|
478
|
+
const runHang = await D.callTool('vibe_v4_lean_run', { file: 'Formal/hang.lean', timeout_ms: 1000 }, r1)
|
|
479
|
+
const waited = Date.now() - t0
|
|
480
|
+
assert(runHang.ok === false && runHang.code === 'LEAN_TIMEOUT' && runHang.timedOut === true, '★ a run that never finishes is reported as LEAN_TIMEOUT (got ' + runHang.code + ')')
|
|
481
|
+
assert(terminated.some(f => /hang\.lean$/.test(String(f))), '★ the timeout path really calls handle.terminate() (docs §7) instead of leaving the Lean process running')
|
|
482
|
+
assert(waited >= 900 && waited < 15000, 'the timeout waited for the cap before terminating (' + waited + 'ms)')
|
|
483
|
+
}
|
|
380
484
|
|
|
381
485
|
// ---------- 5. a passing proof flips the review subject to fidelity ----------
|
|
382
486
|
section('5 a passing proof flips the review subject to fidelity')
|
|
@@ -390,6 +494,18 @@ const stD = await D.callTool('vibe_v4_status', {})
|
|
|
390
494
|
assert(stD.formal.passed.indexOf('p-proof') !== -1, 'status reports the object as Lean-passed')
|
|
391
495
|
const idxD = readIf(join(D.projectRoot, 'Formal', 'Index.md'))
|
|
392
496
|
assert(/p-proof/.test(idxD) && /passed/.test(idxD) && /Verified\/Lean\/p-proof\.lean/.test(idxD), 'Formal/Index.md indexes the object, its status and its archived proof')
|
|
497
|
+
// A later run recorded against an ALREADY-passed object records the run but must never strip
|
|
498
|
+
// `passed`/`proof`: doing so would silently remove the fidelity branch from the next voting prompt
|
|
499
|
+
// AND (in `require`) re-close the gate on an object that already has a green archived proof.
|
|
500
|
+
{
|
|
501
|
+
writeFileSync(join(D.projectRoot, 'Formal', 'p-proof.lean'), 'theorem p_proof : 1 = 2 := by sorry\n', 'utf8')
|
|
502
|
+
const rerun = await D.callTool('vibe_v4_lean_run', { file: 'Formal/p-proof.lean', target: 'p-proof' }, r1)
|
|
503
|
+
assert(rerun.ok === false, 'precondition: the recorded re-run is red')
|
|
504
|
+
const rec = (await D.callTool('vibe_v4_status', {})).formal.objects.find(o => o.target === 'p-proof')
|
|
505
|
+
assert(rec && rec.status === 'passed' && rec.proof === 'Verified/Lean/p-proof.lean',
|
|
506
|
+
'★ a RED re-run never downgrades a `passed` record (docs §31.6: only an explicit re-archive decides) — the object keeps its fidelity prompt and its require-mode gate')
|
|
507
|
+
writeFileSync(join(D.projectRoot, 'Formal', 'p-proof.lean'), 'theorem p_proof : 3 * 1 ^ 2 - 2 = (1:Nat) ^ 2 := by decide\n', 'utf8')
|
|
508
|
+
}
|
|
393
509
|
// a RED proof must NOT mint a Verified/Lean/ copy or mark the object passed
|
|
394
510
|
const arcRed = await D.callTool('vibe_v4_lean_archive', { kind: 'proof', target: 'p-red', content: 'theorem p_red : 1 = 2 := by sorry\n' }, r1)
|
|
395
511
|
assert(arcRed.ok === true && arcRed.passed === false && arcRed.status === 'attempted', 'a red proof is archived as attempted, not passed')
|
|
@@ -420,7 +536,13 @@ assert(!existsSync(join(D.projectRoot, 'Verified', 'Lean', 'p-red.lean')), '★
|
|
|
420
536
|
assert(/你不需要重新检查推导/.test(prompt), '★ it tells voters NOT to re-derive')
|
|
421
537
|
assert(/忠实性审查/.test(prompt), '★ it tells voters the review subject is now fidelity')
|
|
422
538
|
assert(/定义 \/ 对象 \/ 条件 \/ 假设 \/ 结论是否与命题原文\*\*完全一致\*\*/.test(prompt), 'it enumerates exactly what fidelity means')
|
|
423
|
-
assert(
|
|
539
|
+
assert(/一致 → verdict = 1/.test(prompt), "the fidelity instruction uses v4's REAL reply field name (`verdict`)")
|
|
540
|
+
assert(/发现任何偏差,不要投 0/.test(prompt), '★ it forbids expressing a fidelity deviation as "0 / false"')
|
|
541
|
+
assert(/偏差只说明\*\*形式化不合格\*\*,不代表命题为假/.test(prompt), '★ it states WHY: a defect is a failed formalization, not a refutation')
|
|
542
|
+
assert(/formal:\{decision:'defect', note:'<具体偏差>'\}/.test(prompt), '★ it hands the voter the exact `defect` reply contract')
|
|
543
|
+
assert(/降级为 attempted、删除归档证明、写入形式化待办/.test(prompt), 'it says what the framework WILL do with a defect (downgrade + delete + TODO)')
|
|
544
|
+
assert(/只有当你\*\*独立于这份 Lean 代码\*\*也能确定命题为假时,才投 0/.test(prompt), 'only an INDEPENDENT refutation may be expressed as 0')
|
|
545
|
+
assert(!/偏离 → 0/.test(prompt), '★ the old "a deviation ⇒ 0" wording is gone (it would fabricate a negative conclusion)')
|
|
424
546
|
assert(/Verified\/Lean\/p-proof\.lean/.test(prompt), 'it points at the archived proof')
|
|
425
547
|
// the SAME object's work round must not inherit the fidelity framing (that is a voting
|
|
426
548
|
// instruction), but it does carry the standing formalization line.
|
|
@@ -595,6 +717,342 @@ assert(/已通过:.*p-gate/.test(reportE.formalReport), 'the human report list
|
|
|
595
717
|
assert(/已记录阻塞:.*p-blocked-ok/.test(reportE.formalReport), 'the human report lists blocked objects')
|
|
596
718
|
assert(/形式化待办:.*p-gate-false/.test(reportE.formalReport), 'the human report lists the formalization TODO')
|
|
597
719
|
|
|
720
|
+
// ===============================================================
|
|
721
|
+
// 12. the fidelity rule + the prompt hard requirements (docs §6, §10 items 9/11)
|
|
722
|
+
// The v2 lesson (docs §10 item 8) is why every claim here is paired with a BEHAVIOURAL
|
|
723
|
+
// assertion in §13/§14: wording alone guards nothing.
|
|
724
|
+
// ===============================================================
|
|
725
|
+
section('12 the injected text states the fidelity rule and never abbreviates a tool name')
|
|
726
|
+
const G = await establish()
|
|
727
|
+
await G.callTool('vibe_v4_set', { formalVerify: 'encourage' })
|
|
728
|
+
{
|
|
729
|
+
const enc = await G.prompts('verify', 'r-1', { target: 'p-text', stage: 'independent' })
|
|
730
|
+
assert(/【Lean 形式化验证(鼓励模式)】/.test(enc), 'the encourage voting prompt keeps its header')
|
|
731
|
+
assert(/实现难度/.test(enc), 'it still asks for the implementation-difficulty judgement')
|
|
732
|
+
assert(/工具:vibe_v4_lean_run(执行)· vibe_v4_lean_archive(归档)· vibe_v4_lean_lib(查已有可复用库)/.test(enc), 'it names all three tools in FULL')
|
|
733
|
+
assert(/归档可复用定义\/引理前先跑通(vibe_v4_lean_archive run=true 或先 vibe_v4_lean_run);跑不通不要入库。/.test(enc), '★ a reusable definition/lemma must be RUN GREEN before it is archived')
|
|
734
|
+
assert(/宿主没有 Lean 工具链(LEAN_NOT_FOUND)或根本没有 subprocess 服务(NO_SUBPROCESS)时:把代码写下来归档,并在回执的 note 里写明"宿主无 Lean 工具链"/.test(enc), '★ both unavailable-toolchain paths are written out (missing Lean OR no subprocess service) as explicit blocker reasons')
|
|
735
|
+
assert(/一旦 Lean 通过,你唯一需要确认的就是忠实性/.test(enc), 'a green Lean run still shrinks the open question to fidelity')
|
|
736
|
+
assert(/decision='blocked' 时必须写明 note/.test(enc), 'the encourage opt-out documents the mandatory note')
|
|
737
|
+
assert(!/偏离 → 0/.test(enc) && !/发现任何偏离/.test(enc), '★ no "deviation ⇒ 0" instruction anywhere in the encourage block')
|
|
738
|
+
await G.callTool('vibe_v4_set', { formalVerify: 'require' })
|
|
739
|
+
const req = await G.prompts('verify', 'r-1', { target: 'p-text', stage: 'independent' })
|
|
740
|
+
assert(/【Lean 形式化验证(强制模式)】/.test(req), 'the require voting prompt says 强制模式')
|
|
741
|
+
assert(/必须产出 Lean 形式化/.test(req) && /必须\*\*给出显式的阻塞原因/.test(req), "'require' states the formalization OR an explicit blocker is mandatory")
|
|
742
|
+
assert(/本次裁定不会生效/.test(req) && /进入「形式化待办」/.test(req), 'it warns the verdict is withheld as 未定论 (formal-required)')
|
|
743
|
+
assert(!/可以不做/.test(req), "'require' does NOT offer the encourage-mode opt-out")
|
|
744
|
+
assert(/归档可复用定义\/引理前先跑通/.test(req) && /宿主没有 Lean 工具链/.test(req), 'the run-before-archive and toolchain rules are in the require text as well')
|
|
745
|
+
assert(/LEAN_NOT_FOUND/.test(req) && /NO_SUBPROCESS/.test(req), '★ the require text names BOTH unavailable-toolchain codes (the escape route must be documented in every mode)')
|
|
746
|
+
// The sentence is written ONCE and reused by both modes: a second copy would drift (one branch
|
|
747
|
+
// kept up to date, the other stale). The anchor `(LEAN_NOT_FOUND)` therefore occurs exactly once
|
|
748
|
+
// in the plugin, which is also what the sensitivity probe table assumes.
|
|
749
|
+
{
|
|
750
|
+
const src = readFileSync(fileURLToPath(PLUGIN), 'utf8')
|
|
751
|
+
assert(src.split('(LEAN_NOT_FOUND)').length - 1 === 1, '★ the unavailable-toolchain guidance is written once (not duplicated per mode/branch)')
|
|
752
|
+
assert(src.split('(NO_SUBPROCESS)').length - 1 === 1, 'the same single sentence names NO_SUBPROCESS (no per-branch copy)')
|
|
753
|
+
}
|
|
754
|
+
assert(/\*\*本模式要求\*\*/.test(req), 'the require bullet replaces the encourage opt-out in place')
|
|
755
|
+
// normal / heartbeat / post-compact recap all carry the standing work line; the two that ARE a
|
|
756
|
+
// reply contract also document the `defect` decision (coreRules is a recap prefix, not a contract)
|
|
757
|
+
for (const [label, text] of [['normal', await G.prompts('normal', 'r-1')], ['heartbeat', await G.prompts('heartbeat', 'r-1')], ['coreRules', await G.prompts('coreRules', 'r-1')]]) {
|
|
758
|
+
assert(/【顺手形式化(强制)】/.test(text), label + ': the standing formalization line uses the require wording')
|
|
759
|
+
assert(/归档前先跑通(vibe_v4_lean_run 或 run=true);跑不通的定义不要进可复用库。/.test(text), label + ': ★ it requires a green run before archiving a reusable definition')
|
|
760
|
+
if (label !== 'coreRules') assert(/"decision":"used\|blocked\|defect"/.test(text), label + ': the reply contract documents the `defect` decision')
|
|
761
|
+
}
|
|
762
|
+
assert(/"decision":"used\|blocked\|defect"/.test(req) && /具体偏差/.test(req), '★ the voting reply contract documents decision=defect and its note')
|
|
763
|
+
}
|
|
764
|
+
{
|
|
765
|
+
// ---- the sweep: EVERY agent-facing string must spell the three tools in full (docs §6-1) ----
|
|
766
|
+
const scanned = []
|
|
767
|
+
const addText = (label, t) => { if (typeof t === 'string' && t) scanned.push({ label, text: t }) }
|
|
768
|
+
addText('captured run prompts', G.allPrompts())
|
|
769
|
+
for (const which of ['brainstorm', 'normal', 'heartbeat', 'coreRules']) addText(which, await G.prompts(which, 'r-1'))
|
|
770
|
+
for (const t of ['p-text', 'p-corpus']) for (const st of ['independent', 'debate']) addText('verify:' + t + ':' + st, await G.prompts('verify', 'r-1', { target: t, stage: st }))
|
|
771
|
+
// tool hints are injected text too (docs §6 hard requirement 1 names them explicitly)
|
|
772
|
+
const r1G = G.resAgent(G.childOf('r-1'))
|
|
773
|
+
const hintGreen = await G.callTool('vibe_v4_lean_archive', { kind: 'proof', target: 'p-hint', content: 'theorem p_hint : 1 = 1 := rfl\n' }, r1G)
|
|
774
|
+
assert(hintGreen.ok === true && hintGreen.passed === true, 'precondition: a green file exists for the hint sweep')
|
|
775
|
+
const hintRed = await G.callTool('vibe_v4_lean_archive', { kind: 'proof', target: 'p-hint-red', content: 'theorem p_hint_red : 1 = 2 := by sorry\n' }, r1G)
|
|
776
|
+
assert(hintRed.ok === true && hintRed.passed === false, 'precondition: a red file exists for the hint sweep')
|
|
777
|
+
addText('lean_run hint (green)', (await G.callTool('vibe_v4_lean_run', { file: 'Formal/p-hint.lean' }, r1G)).hint)
|
|
778
|
+
addText('lean_run hint (red)', (await G.callTool('vibe_v4_lean_run', { file: 'Formal/p-hint-red.lean' }, r1G)).hint)
|
|
779
|
+
addText('lean_lib hint', (await G.callTool('vibe_v4_lean_lib', {}, r1G)).hint)
|
|
780
|
+
toolchainAvailable = false
|
|
781
|
+
addText('LEAN_NOT_FOUND message', (await G.callTool('vibe_v4_lean_run', { file: 'Formal/p-hint.lean' }, r1G)).message)
|
|
782
|
+
toolchainAvailable = true
|
|
783
|
+
for (const t of G.toolRegs.filter((x) => /lean/.test(x.name))) addText('tool description ' + t.name, t.description)
|
|
784
|
+
// The activity log is agent/host-readable text too (vibe_v4_report exposes `recentActivity`, and
|
|
785
|
+
// a host reads it out to the group): a bare abbreviation there names a tool that does not exist,
|
|
786
|
+
// for exactly the same reason as in a prompt.
|
|
787
|
+
try {
|
|
788
|
+
const log = JSON.parse(readIf(join(G.projectRoot, 'State', 'session.json')) || '{}').activityLog || []
|
|
789
|
+
for (const e of log) addText('activity log: ' + e.event, String((e && e.detail) || ''))
|
|
790
|
+
} catch (e) { /* the log is best-effort */ }
|
|
791
|
+
const bare = [/(^|[^a-z_])lean_run/, /(^|[^a-z_])lean_archive/, /(^|[^a-z_])lean_lib/]
|
|
792
|
+
const offenders = []
|
|
793
|
+
for (const s of scanned) for (const re of bare) if (re.test(s.text)) offenders.push(s.label + ' :: ' + re.source)
|
|
794
|
+
assert(offenders.length === 0, '★ no injected text (prompt, tool hint or tool description) uses a bare tool abbreviation (' + offenders.slice(0, 3).join(' | ') + ')')
|
|
795
|
+
assert(scanned.length >= 15, 'the sweep really covered the injected-text surface (' + scanned.length + ' texts)')
|
|
796
|
+
}
|
|
797
|
+
{
|
|
798
|
+
// docs §4.1-3 / §6.1: the fidelity branch's "the framework withholds the verdict" clause may only
|
|
799
|
+
// appear in `require` (the only mode with a gate). In `encourage` the framework still withdraws
|
|
800
|
+
// the proof and records the TODO, but it CANNOT hold the ballot — so the text must not promise
|
|
801
|
+
// that, and must instead point at the voter's own abstention.
|
|
802
|
+
await G.callTool('vibe_v4_set', { formalVerify: 'require' })
|
|
803
|
+
const reqFid = await G.prompts('verify', 'r-1', { target: 'p-hint', stage: 'independent' })
|
|
804
|
+
assert(/该对象已有\*\*通过的 Lean 形式化证明\*\*/.test(reqFid), 'precondition: p-hint is the passed/fidelity case in this prompt')
|
|
805
|
+
assert(/本次裁定\*\*不定论\*\*/.test(reqFid), "'require' fidelity text states the verdict will be withheld (it has a gate)")
|
|
806
|
+
await G.callTool('vibe_v4_set', { formalVerify: 'encourage' })
|
|
807
|
+
const encFid = await G.prompts('verify', 'r-1', { target: 'p-hint', stage: 'independent' })
|
|
808
|
+
assert(!/本次裁定\*\*不定论\*\*/.test(encFid), "★ 'encourage' does NOT promise a hold it cannot enforce (docs §4.1-3)")
|
|
809
|
+
assert(/本档没有门禁/.test(encFid) && /弃权值/.test(encFid), "★ instead it says the voter's own abstention is what keeps the ballot from concluding")
|
|
810
|
+
assert(/降级为 attempted、删除归档证明、写入形式化待办/.test(encFid), 'the withdrawal the framework CAN enforce is still stated in both modes')
|
|
811
|
+
assert(/发现任何偏差,不要投 0/.test(encFid), 'the fidelity rule itself is mode-independent')
|
|
812
|
+
await G.callTool('vibe_v4_set', { formalVerify: 'require' })
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
// ===============================================================
|
|
816
|
+
// 13. the `defect` reply channel (docs §4.1 / §10 item 8) — BEHAVIOURAL, not wording
|
|
817
|
+
// ===============================================================
|
|
818
|
+
section('13 the `defect` reply withdraws a passing proof (spec §4.1)')
|
|
819
|
+
await G.callTool('vibe_v4_set', { formalVerify: 'encourage' })
|
|
820
|
+
const activityOf = (h) => { try { return JSON.parse(readIf(join(h.projectRoot, 'State', 'session.json')) || '{}').activityLog || [] } catch (e) { return [] } }
|
|
821
|
+
const g1 = G.resAgent(G.childOf('r-1'))
|
|
822
|
+
{
|
|
823
|
+
const arc = await G.callTool('vibe_v4_lean_archive', { kind: 'proof', target: 'p-defect', content: 'theorem p_defect : 2 + 2 = 4 := by decide\n' }, g1)
|
|
824
|
+
assert(arc.passed === true && existsSync(join(G.projectRoot, 'Verified', 'Lean', 'p-defect.lean')), 'precondition: p-defect has a green archived proof')
|
|
825
|
+
const w = await workWake(G, 'r-1')
|
|
826
|
+
G.fireEnd(w.childId, { summary: '我逐条核对了 Lean 代码,发现偏差。', formal: { target: 'p-defect', decision: 'defect', note: 'Lean 里的条件比命题弱:只证了 n ≥ 1 的情形' }, contextPct: 20 })
|
|
827
|
+
await sleep(90)
|
|
828
|
+
const st = await G.callTool('vibe_v4_status', {})
|
|
829
|
+
const rec = st.formal.objects.find((o) => o.target === 'p-defect')
|
|
830
|
+
assert(rec && rec.status === 'attempted', '★ a `formal.decision=defect` reply downgrades the object to attempted (never a refutation)')
|
|
831
|
+
assert(rec && rec.proof === '', '★ the archived proof is cleared from the record')
|
|
832
|
+
assert(rec && rec.note === 'Lean 里的条件比命题弱:只证了 n ≥ 1 的情形', 'the concrete deviation is stored as the record note')
|
|
833
|
+
assert(!existsSync(join(G.projectRoot, 'Verified', 'Lean', 'p-defect.lean')), '★ the archived proof file is DELETED (the formalization is 不合格 — the proposition is NOT false)')
|
|
834
|
+
assert(existsSync(join(G.projectRoot, 'Formal', 'p-defect.lean')), 'the WORKING file is kept — the code is not lost, only its "passed" claim')
|
|
835
|
+
assert(st.formal.passed.indexOf('p-defect') === -1, 'the object is no longer reported as Lean-passed')
|
|
836
|
+
assert(shellCalls.some((c) => /Remove-Item|^rm -f/.test(c) && /p-defect\.lean/.test(c)), 'the withdrawal really went through the platform shell (the fs service has no delete)')
|
|
837
|
+
const todo = readIf(join(G.projectRoot, 'Formal', 'TODO.md'))
|
|
838
|
+
assert(/p-defect/.test(todo) && /formal-defect/.test(todo), '★ Formal/TODO.md lists the object with the DEFECT reason')
|
|
839
|
+
assert(/只证了 n ≥ 1 的情形/.test(todo), '★ the concrete deviation reaches the human-readable TODO')
|
|
840
|
+
const idx = readIf(join(G.projectRoot, 'Formal', 'Index.md'))
|
|
841
|
+
assert(/\| p-defect \| attempted \|/.test(idx), 'Formal/Index.md downgrades the object to attempted')
|
|
842
|
+
assert(/只证了 n ≥ 1 的情形/.test(idx), 'the deviation is the record note in the index')
|
|
843
|
+
assert(activityOf(G).some((e) => /忠实性缺陷/.test(e.detail) && /p-defect/.test(e.detail)), '★ the retraction is announced in the activity log')
|
|
844
|
+
// the log line is agent/host-readable text, so it is bound by the same §4.1-3 rule as the prompt:
|
|
845
|
+
// in `encourage` it may not claim a hold the mode does not have.
|
|
846
|
+
{
|
|
847
|
+
const line = activityOf(G).filter((e) => /忠实性缺陷/.test(e.detail) && /p-defect[^-]/.test(e.detail)).pop() || { detail: '' }
|
|
848
|
+
assert(/本档没有门禁/.test(line.detail) && !/本次裁定\*\*不定论\*\*/.test(line.detail), "★ the encourage-mode activity line does not promise the 不定论 hold that only `require` enforces")
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
{
|
|
852
|
+
// §4.1 degraded withdrawal: the record must never be the ONLY thing withdrawn. A host whose shell
|
|
853
|
+
// "succeeds" without deleting (a stub host / a permissions quirk) must be caught by re-reading the
|
|
854
|
+
// file through the fs service, and the archive must then be OVERWRITTEN with a withdrawal notice —
|
|
855
|
+
// otherwise the retracted proof keeps sitting at the exact path everyone looks for the proof.
|
|
856
|
+
const arcD = await G.callTool('vibe_v4_lean_archive', { kind: 'proof', target: 'p-defect-degraded', content: 'theorem p_defect_degraded : 5 = 5 := rfl\n' }, g1)
|
|
857
|
+
assert(arcD.passed === true && existsSync(join(G.projectRoot, 'Verified', 'Lean', 'p-defect-degraded.lean')), 'precondition: the degraded-path object has a green archived proof')
|
|
858
|
+
shellDeletesFiles = false
|
|
859
|
+
const wD = await workWake(G, 'r-1')
|
|
860
|
+
G.fireEnd(wD.childId, { summary: '核对后发现偏差。', formal: { target: 'p-defect-degraded', decision: 'defect', note: '结论方向相反' }, contextPct: 20 })
|
|
861
|
+
await sleep(90)
|
|
862
|
+
shellDeletesFiles = true
|
|
863
|
+
const body = readIf(join(G.projectRoot, 'Verified', 'Lean', 'p-defect-degraded.lean'))
|
|
864
|
+
assert(!/p_defect_degraded/.test(body), '★ a shell that exits 0 without deleting does NOT leave the retracted proof readable — its original text is gone')
|
|
865
|
+
assert(/已撤回/.test(body) && /原代码保留在工作文件/.test(body), '★ the archived file was OVERWRITTEN with an explicit withdrawal notice instead (delete → confirm → overwrite)')
|
|
866
|
+
const recD = (await G.callTool('vibe_v4_status', {})).formal.objects.find((o) => o.target === 'p-defect-degraded')
|
|
867
|
+
assert(recD && recD.status === 'attempted' && recD.proof === '', 'the record is downgraded on the degraded path too')
|
|
868
|
+
assert(activityOf(G).some((e) => /覆盖归档证明/.test(e.detail) && /p-defect-degraded/.test(e.detail)), '★ the activity log says WHICH withdrawal path was taken (overwritten, not silently reported as deleted)')
|
|
869
|
+
}
|
|
870
|
+
{
|
|
871
|
+
const arc2 = await G.callTool('vibe_v4_lean_archive', { kind: 'proof', target: 'p-defect2', content: 'theorem p_defect2 : 3 + 3 = 6 := by decide\n' }, g1)
|
|
872
|
+
assert(arc2.passed === true, 'precondition: p-defect2 is Lean-passed')
|
|
873
|
+
const w2 = await workWake(G, 'r-2')
|
|
874
|
+
G.fireEnd(w2.childId, { summary: '有偏差,但没写清是什么。', formal: { target: 'p-defect2', decision: 'defect' }, contextPct: 20 })
|
|
875
|
+
await sleep(90)
|
|
876
|
+
const st2 = await G.callTool('vibe_v4_status', {})
|
|
877
|
+
const rec2 = st2.formal.objects.find((o) => o.target === 'p-defect2')
|
|
878
|
+
assert(rec2 && rec2.status === 'passed' && rec2.proof === 'Verified/Lean/p-defect2.lean', '★ a `defect` reply WITHOUT a note is REJECTED — the record is untouched')
|
|
879
|
+
assert(existsSync(join(G.projectRoot, 'Verified', 'Lean', 'p-defect2.lean')), '★ and the archived proof is NOT withdrawn')
|
|
880
|
+
assert(activityOf(G).some((e) => /defect/.test(e.detail) && /V4_INVALID_ARGUMENT/.test(e.detail)), '★ the rejection carries the preset error code (V4_INVALID_ARGUMENT), not a silent drop')
|
|
881
|
+
assert((await G.callTool('vibe_v4_status', {})).ok === true, 'the refusal did not crash the run')
|
|
882
|
+
}
|
|
883
|
+
{
|
|
884
|
+
const blk = await G.callTool('vibe_v4_lean_archive', { kind: 'blocked', target: 'p-defect3', note: '前置知识未形式化,本轮不做' }, g1)
|
|
885
|
+
assert(blk.ok === true && blk.status === 'blocked', 'precondition: p-defect3 carries a reasoned blocker record')
|
|
886
|
+
const w3 = await workWake(G, 'r-1')
|
|
887
|
+
G.fireEnd(w3.childId, { summary: '复核后发现归档的形式化换了对象。', formal: { target: 'p-defect3', decision: 'defect', note: '归档的形式化证的是特例,换了对象' }, contextPct: 20 })
|
|
888
|
+
await sleep(90)
|
|
889
|
+
const st3 = await G.callTool('vibe_v4_status', {})
|
|
890
|
+
const rec3 = st3.formal.objects.find((o) => o.target === 'p-defect3')
|
|
891
|
+
assert(rec3 && rec3.status === 'attempted', '★ `defect` downgrades even a `blocked` record (spec §4.1: ALWAYS downgrade)')
|
|
892
|
+
assert(st3.formal.blocked.indexOf('p-defect3') === -1, '★ a bad formalization may not stay in the gate-passing `blocked` state')
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
// ===============================================================
|
|
896
|
+
// 14. `require` after a defect: the retraction closes the gate (docs §4.1-3 / §10 item 9)
|
|
897
|
+
// ===============================================================
|
|
898
|
+
section("14 'require' withholds the verdict after a defect, even on a unanimous 1")
|
|
899
|
+
const H = await establish()
|
|
900
|
+
await H.callTool('vibe_v4_set', { formalVerify: 'require' })
|
|
901
|
+
{
|
|
902
|
+
const h1 = H.resAgent(H.childOf('r-1'))
|
|
903
|
+
const arc = await H.callTool('vibe_v4_lean_archive', { kind: 'proof', target: 'p-defect-req', content: 'theorem p_defect_req : 4 * 1 ^ 2 - 2 = (1:Nat) ^ 2 := by decide\n' }, h1)
|
|
904
|
+
assert(arc.passed === true, 'precondition: p-defect-req is Lean-passed')
|
|
905
|
+
const before = await H.prompts('verify', 'r-1', { target: 'p-defect-req', stage: 'independent' })
|
|
906
|
+
assert(/不要投 0/.test(before) && /formal:\{decision:'defect'/.test(before), 'the voter is told (before voting) how to report a fidelity defect')
|
|
907
|
+
await H.callTool('vibe_v4_record_proposition', { id: 'p-defect-req', title: '缺陷不是证伪', statement: '形式化写窄了不代表命题为假', prob: 0.9, value: 0.6, motivation: 'm' }, h1)
|
|
908
|
+
const n0 = H.followups.length
|
|
909
|
+
await H.callTool('vibe_v4_message', { to: 'r-1', content: '请处理本轮工作。' })
|
|
910
|
+
for (let i = 0; i < 300 && H.followups.length === n0; i++) await sleep(10)
|
|
911
|
+
// r-1 reports the defect AND votes 1 in the SAME reply; r-2 votes 1. The framework must NOT take
|
|
912
|
+
// the unanimous 1: the formalization was just retracted, so the verdict has to be deferred.
|
|
913
|
+
const replyFor = (pt, rId) => (/团队验证/.test(pt)
|
|
914
|
+
? (rId === 'r-1'
|
|
915
|
+
? { vote: { verdict: 1, reason: '我发现形式化写窄了,但独立看命题仍为真' }, formal: { target: 'p-defect-req', decision: 'defect', note: 'Lean 只证了 x=1 的特例,命题要求所有整数 x' } }
|
|
916
|
+
: { vote: { verdict: 1, reason: '独立复核为真' } })
|
|
917
|
+
: { summary: '提议验证 p-defect-req。', solved: false, propose_verify: 'p-defect-req', contextPct: 20 })
|
|
918
|
+
for (let i = 0; i < 4; i++) { await drive(H, replyFor, verifySettled(H)); if (await verifySettled(H)()) break }
|
|
919
|
+
const st = await H.callTool('vibe_v4_status', {})
|
|
920
|
+
assert(st.verifyInProgress === false && st.pendingVerify === null, 'the verification actually settled (so the next assertion is falsifiable)')
|
|
921
|
+
assert(!existsSync(join(H.projectRoot, 'Verified', '命题', 'p-defect-req.md')), '★ a defect in `require` mode writes NO Verified card, even with a unanimous 1')
|
|
922
|
+
assert(st.formal.todo.indexOf('p-defect-req') !== -1, '★ the object stays 未定论 on the formalization TODO')
|
|
923
|
+
const rec = st.formal.objects.find((o) => o.target === 'p-defect-req')
|
|
924
|
+
assert(rec && rec.status === 'attempted' && rec.proof === '', 'the formal record is the retracted one (attempted, no proof)')
|
|
925
|
+
assert(rec && /只证了 x=1 的特例/.test(rec.note || ''), "the record's note is the reported deviation")
|
|
926
|
+
assert(!existsSync(join(H.projectRoot, 'Verified', 'Lean', 'p-defect-req.lean')), '★ the archived proof was withdrawn as part of the retraction')
|
|
927
|
+
assert(!/已验证·真/.test(readIf(join(H.projectRoot, 'Propos', 'r-1', 'p-defect-req.md'))), 'the source card was NOT rewritten to 已验证·真 (the conclusion was withheld, not taken)')
|
|
928
|
+
assert(!/已验证·真/.test(readIf(join(H.projectRoot, 'Shared', 'debates', 'p-defect-req.md'))), 'the debate record does not claim a 真 conclusion')
|
|
929
|
+
const todo = readIf(join(H.projectRoot, 'Formal', 'TODO.md'))
|
|
930
|
+
assert(/p-defect-req/.test(todo) && /formal-defect/.test(todo), '★ the TODO keeps the DEFECT reason, not merely formal-required')
|
|
931
|
+
assert(/只证了 x=1 的特例/.test(todo), 'the concrete deviation is what a human reads in the TODO')
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
// ===============================================================
|
|
935
|
+
// 15. the shipped Lean prompt corpus (docs §10 item 10) — a HUMAN must be able to re-read the
|
|
936
|
+
// exact text, not just the assertions about it.
|
|
937
|
+
// ===============================================================
|
|
938
|
+
section('15 the captured Lean prompt corpus is written for human review')
|
|
939
|
+
const K = await establish()
|
|
940
|
+
{
|
|
941
|
+
const vibe = K.vibeRoot
|
|
942
|
+
// Normalise BOTH slash forms, and the VibeMath root FIRST: it sits INSIDE the workspace, so
|
|
943
|
+
// replacing the workspace first would leave `<WS>/VibeMath` instead of `<VIBEMATH>`.
|
|
944
|
+
const scrub = (s) => String(s == null ? '' : s)
|
|
945
|
+
.split(vibe).join('<VIBEMATH>').split(vibe.replace(/\\/g, '/')).join('<VIBEMATH>')
|
|
946
|
+
.split(K.WS).join('<WS>').split(K.WS.replace(/\\/g, '/')).join('<WS>')
|
|
947
|
+
const corpus = []
|
|
948
|
+
const add = (kind, label, prompt) => corpus.push({ kind, label, prompt: scrub(prompt) })
|
|
949
|
+
// (a) off: a TRUE no-op must be visible in the corpus, not merely asserted
|
|
950
|
+
add('verify', 'off/verify', await K.prompts('verify', 'r-1', { target: 'p-corpus', stage: 'independent' }))
|
|
951
|
+
add('work', 'off/normal', await K.prompts('normal', 'r-1'))
|
|
952
|
+
// (b) encourage
|
|
953
|
+
await K.callTool('vibe_v4_set', { formalVerify: 'encourage' })
|
|
954
|
+
add('verify', 'encourage/verify', await K.prompts('verify', 'r-1', { target: 'p-corpus', stage: 'independent' }))
|
|
955
|
+
const encNormal = await K.prompts('normal', 'r-1')
|
|
956
|
+
add('work', 'encourage/normal', encNormal)
|
|
957
|
+
add('work', 'encourage/heartbeat', await K.prompts('heartbeat', 'r-1'))
|
|
958
|
+
add('work', 'encourage/coreRules', await K.prompts('coreRules', 'r-1'))
|
|
959
|
+
// (c) require
|
|
960
|
+
await K.callTool('vibe_v4_set', { formalVerify: 'require' })
|
|
961
|
+
add('verify', 'require/verify', await K.prompts('verify', 'r-1', { target: 'p-corpus', stage: 'independent' }))
|
|
962
|
+
add('verify', 'require/verify/debate', await K.prompts('verify', 'r-1', { target: 'p-corpus', stage: 'debate' }))
|
|
963
|
+
add('work', 'require/normal', await K.prompts('normal', 'r-1'))
|
|
964
|
+
// (d) a PASSED object: the review subject has changed to fidelity
|
|
965
|
+
const k1 = K.resAgent(K.childOf('r-1'))
|
|
966
|
+
await K.callTool('vibe_v4_lean_archive', { kind: 'proof', target: 'p-corpus-passed', content: 'theorem p_corpus_passed : 1 + 1 = 2 := by decide\n' }, k1)
|
|
967
|
+
const fid = await K.prompts('verify', 'r-1', { target: 'p-corpus-passed', stage: 'independent' })
|
|
968
|
+
add('verify', 'passed/fidelity', fid)
|
|
969
|
+
// (d2) the SAME passed object in `encourage`: the promise must shrink to what that mode enforces
|
|
970
|
+
// (docs §4.1-3: no gate there, so no claim that the framework withholds the verdict).
|
|
971
|
+
await K.callTool('vibe_v4_set', { formalVerify: 'encourage' })
|
|
972
|
+
const fidEnc = await K.prompts('verify', 'r-1', { target: 'p-corpus-passed', stage: 'independent' })
|
|
973
|
+
add('verify', 'passed/fidelity (encourage)', fidEnc)
|
|
974
|
+
await K.callTool('vibe_v4_set', { formalVerify: 'require' })
|
|
975
|
+
// (e) a BLOCKED object
|
|
976
|
+
await K.callTool('vibe_v4_lean_archive', { kind: 'blocked', target: 'p-corpus-blocked', note: '需要未形式化的解析数论框架' }, k1)
|
|
977
|
+
add('verify', 'blocked/verify', await K.prompts('verify', 'r-1', { target: 'p-corpus-blocked', stage: 'independent' }))
|
|
978
|
+
// (f) the `formal` reply contract line itself (the field whose parsing §13/§14 prove)
|
|
979
|
+
const contractLine = (t) => { const m = String(t).match(/"formal":\{[^\n]*\}\}/); return m ? m[0] : '' }
|
|
980
|
+
add('contract', 'formal reply contract (voting prompt)', contractLine(fid))
|
|
981
|
+
add('contract', 'formal reply contract (work prompt)', contractLine(encNormal))
|
|
982
|
+
// (g) a REAL delivered work wake (proves the builder is the one actually used to address a resident)
|
|
983
|
+
const w = await workWake(K, 'r-2')
|
|
984
|
+
add('work', 'require/real work wake', promptOf(w))
|
|
985
|
+
K.fireEnd(w.childId, { summary: '继续推进。', solved: false, contextPct: 20 })
|
|
986
|
+
await sleep(40)
|
|
987
|
+
// (h) the tool hints are injected text too (docs §6 hard requirement 1)
|
|
988
|
+
add('hint', 'lean_run hint (green)', (await K.callTool('vibe_v4_lean_run', { file: 'Formal/p-corpus-passed.lean' }, k1)).hint)
|
|
989
|
+
add('hint', 'lean_lib hint', (await K.callTool('vibe_v4_lean_lib', {}, k1)).hint)
|
|
990
|
+
|
|
991
|
+
// The corpus is REGENERATED on every run. Dumping it while V4_PLUGIN points at a MUTATED copy
|
|
992
|
+
// would let a sensitivity probe overwrite the SHIPPED corpus with mutated text (the probe's job
|
|
993
|
+
// is to run this suite against a broken plugin), so the dump is skipped then — unless the probe
|
|
994
|
+
// explicitly redirects it with V4_CORPUS_DIR. The IN-MEMORY corpus assertions below still run, so
|
|
995
|
+
// nothing is weakened.
|
|
996
|
+
const writeCorpus = !process.env.V4_PLUGIN || !!process.env.V4_CORPUS_DIR
|
|
997
|
+
if (writeCorpus) {
|
|
998
|
+
mkdirSync(CORPUS_DIR, { recursive: true })
|
|
999
|
+
writeFileSync(join(CORPUS_DIR, 'formal-verify-v4.json'), JSON.stringify({ entries: corpus }, null, 2), 'utf8')
|
|
1000
|
+
const md = ['# V4 形式化验证交互语料(prompt corpus)', '',
|
|
1001
|
+
'> 由 `formal-verify-v4.test.mjs` 落盘:非 `off` 模式下常驻**真正会读到**的 Lean 提示词原文',
|
|
1002
|
+
'> (`vibe_v4_prompts` 的只读回显 + 一条真实投递的工作轮 + 工具 `hint`)。',
|
|
1003
|
+
'> 工作区路径归一化为 `<WS>`,VibeMath 根归一化为 `<VIBEMATH>`:确定、可 diff、不含任何本机路径。', '',
|
|
1004
|
+
'> 覆盖:`off`(无 Lean 文本)、`encourage`、**`require`**、对象 `passed` 后的**忠实性分支**',
|
|
1005
|
+
'> (`encourage` / `require` 两种措辞各一份:只有 `require` 会声称"不定论")、',
|
|
1006
|
+
'> `blocked` 分支、平时工作轮的「顺手形式化」,以及回执契约里的 `formal` 字段。', '']
|
|
1007
|
+
for (let i = 0; i < corpus.length; i++) {
|
|
1008
|
+
const c = corpus[i]
|
|
1009
|
+
md.push('## [' + i + '] ' + c.kind + ' · ' + c.label)
|
|
1010
|
+
md.push('')
|
|
1011
|
+
md.push('```text')
|
|
1012
|
+
md.push(c.prompt)
|
|
1013
|
+
md.push('```')
|
|
1014
|
+
md.push('')
|
|
1015
|
+
}
|
|
1016
|
+
writeFileSync(join(CORPUS_DIR, 'formal-verify-v4.md'), md.join('\n'), 'utf8')
|
|
1017
|
+
assert(existsSync(join(CORPUS_DIR, 'formal-verify-v4.json')) && existsSync(join(CORPUS_DIR, 'formal-verify-v4.md')), 'the prompt corpus was written (JSON + Markdown)')
|
|
1018
|
+
}
|
|
1019
|
+
assert(corpus.length >= 14, 'the corpus covers the whole Lean prompt surface (' + corpus.length + ' prompts)')
|
|
1020
|
+
const byLabel = (l) => corpus.find((c) => c.label === l)
|
|
1021
|
+
assert(!!byLabel('off/verify') && !/Lean/.test(byLabel('off/verify').prompt) && !/Lean/.test(byLabel('off/normal').prompt), '★ the corpus keeps the off-mode entries and they contain NO Lean text')
|
|
1022
|
+
assert(/【Lean 形式化验证(鼓励模式)】/.test(byLabel('encourage/verify').prompt), 'the corpus carries the encourage voting prompt')
|
|
1023
|
+
assert(/【Lean 形式化验证(强制模式)】/.test(byLabel('require/verify').prompt), '★ the corpus carries the REQUIRE voting prompt')
|
|
1024
|
+
assert(/不要投 0/.test(byLabel('passed/fidelity').prompt), '★ the corpus carries the passed/fidelity branch')
|
|
1025
|
+
assert(/本次裁定\*\*不定论\*\*/.test(byLabel('passed/fidelity').prompt), 'the require fidelity entry keeps the hold it really enforces')
|
|
1026
|
+
assert(!!byLabel('passed/fidelity (encourage)') && !/本次裁定\*\*不定论\*\*/.test(byLabel('passed/fidelity (encourage)').prompt)
|
|
1027
|
+
&& /本档没有门禁/.test(byLabel('passed/fidelity (encourage)').prompt), '★ the encourage fidelity entry does NOT promise the hold only require has (docs §4.1-3)')
|
|
1028
|
+
assert(/【顺手形式化(强制)】/.test(byLabel('require/normal').prompt), 'the corpus carries the ordinary work-round line')
|
|
1029
|
+
assert(/"decision":"used\|blocked\|defect"/.test(byLabel('formal reply contract (voting prompt)').prompt), '★ the corpus carries the `formal` reply contract line with decision=defect')
|
|
1030
|
+
assert(/【顺手形式化/.test(byLabel('require/real work wake').prompt), 'the corpus also keeps a prompt the framework REALLY delivered')
|
|
1031
|
+
const joined = corpus.map((c) => c.prompt).join('\n')
|
|
1032
|
+
assert(joined.indexOf(K.WS) === -1 && joined.indexOf(K.WS.replace(/\\/g, '/')) === -1 && joined.indexOf(vibe) === -1 && joined.indexOf(vibe.replace(/\\/g, '/')) === -1, '★ every captured prompt normalises <WS> and <VIBEMATH> (diffable, no machine paths)')
|
|
1033
|
+
assert(!/\[object Object\]|\bNaN\b|:\s*undefined|["']undefined["']|undefined\s*[,}\]]/.test(joined), 'no captured prompt contains placeholder garbage')
|
|
1034
|
+
assert(corpus.every((c) => c.prompt && c.prompt.length > 20), 'every corpus entry carries real prompt text')
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
// ===============================================================
|
|
1038
|
+
// 16. a FRESH run must not inherit the previous run's formal records (docs §31.6): object ids are
|
|
1039
|
+
// reused (p-*, r-1..), so the in-memory reset in `start()` has to REACH DISK even when the mode
|
|
1040
|
+
// has been switched back to `off` — otherwise a later `resume` restores a stale `passed` and
|
|
1041
|
+
// re-opens the require gate for an object of the new run. This is the exact hazard that makes
|
|
1042
|
+
// the `off`-mode persistence guard ("do not create State/formal.json" ) non-trivial.
|
|
1043
|
+
// ===============================================================
|
|
1044
|
+
section('16 a fresh run clears the persisted formal records (even in off mode)')
|
|
1045
|
+
{
|
|
1046
|
+
const stale = readIf(join(D.projectRoot, 'State', 'formal.json'))
|
|
1047
|
+
assert(/"p-proof"/.test(stale), 'precondition: the previous run left formal records on disk')
|
|
1048
|
+
await D.callTool('vibe_v4_set', { formalVerify: 'off' })
|
|
1049
|
+
const beforeSpawns = D.spawns.length
|
|
1050
|
+
const st = await D.callTool('vibe_v4_start', { problem: '新一轮:形式化清白起点', residentCount: 1 })
|
|
1051
|
+
assert(st.ok === true && D.spawns.length > beforeSpawns, 'the fresh run actually started (so the clean-slate assertion is falsifiable)')
|
|
1052
|
+
const now = readIf(join(D.projectRoot, 'State', 'formal.json'))
|
|
1053
|
+
assert(!/"p-proof"/.test(now) && !/"passed"/.test(now), '★ a fresh run clears the persisted formal records on disk, even in off mode (no stale `passed` can open the new run’s gate)')
|
|
1054
|
+
}
|
|
1055
|
+
|
|
598
1056
|
// ===============================================================
|
|
599
1057
|
console.log('')
|
|
600
1058
|
console.log('passed=' + passed + ' failed=' + failed)
|