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
|
@@ -22,20 +22,23 @@
|
|
|
22
22
|
//
|
|
23
23
|
// Run: node audit-formal-sensitivity.mjs
|
|
24
24
|
// ============================================================
|
|
25
|
-
import { readFileSync, writeFileSync, mkdtempSync, rmSync } from 'node:fs'
|
|
25
|
+
import { readFileSync, writeFileSync, mkdtempSync, rmSync, mkdirSync } from 'node:fs'
|
|
26
26
|
import { tmpdir } from 'node:os'
|
|
27
27
|
import { join } from 'node:path'
|
|
28
|
-
import { spawnSync } from 'node:child_process'
|
|
28
|
+
import { spawn, spawnSync } from 'node:child_process'
|
|
29
|
+
import { cpus } from 'node:os'
|
|
29
30
|
import { fileURLToPath } from 'node:url'
|
|
30
31
|
|
|
31
32
|
const REPO = fileURLToPath(new URL('.', import.meta.url))
|
|
32
33
|
const dir = mkdtempSync(join(tmpdir(), 'v5-formal-sens-'))
|
|
33
34
|
|
|
34
35
|
const PLUGINS = {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
// corpusEnv: each suite writes a human-reviewable prompt corpus; concurrent probes of the SAME
|
|
37
|
+
// suite must not race on it, so every probe gets its own corpus dir.
|
|
38
|
+
v2: { file: join(REPO, 'vibe-math-v2', 'vibe-math-v2.js'), suite: 'formal-verify-v2.test.mjs', env: 'V2_PLUGIN', corpusEnv: 'V2_CORPUS_DIR' },
|
|
39
|
+
v3: { file: join(REPO, 'vibe-math-v3', 'vibe-math-v3.js'), suite: 'formal-verify-v3.test.mjs', env: 'V3_PLUGIN', corpusEnv: 'V3_CORPUS_DIR' },
|
|
40
|
+
v4: { file: join(REPO, 'vibe-math-v4', 'vibe-math-v4.js'), suite: 'formal-verify-v4.test.mjs', env: 'V4_PLUGIN', corpusEnv: 'V4_CORPUS_DIR' },
|
|
41
|
+
v5: { file: join(REPO, 'vibe-math-v5', 'vibe-math-v5.js'), suite: 'formal-verify-v5.test.mjs', env: 'V5_PLUGIN', corpusEnv: 'V5_CORPUS_DIR' },
|
|
39
42
|
}
|
|
40
43
|
const ORIGINAL = {}
|
|
41
44
|
for (const [k, v] of Object.entries(PLUGINS)) ORIGINAL[k] = readFileSync(v.file, 'utf8')
|
|
@@ -191,56 +194,148 @@ const probes = [
|
|
|
191
194
|
to: ", 'vibe_math_lean_run_DISABLED')" },
|
|
192
195
|
]
|
|
193
196
|
|
|
197
|
+
// ── prompt-surface probes (2.3.1) ────────────────────────────────────────────────────────
|
|
198
|
+
// "成员读到的文字就是产品" (AUDIT-CHECKLIST §0): the injected text is a contract, so breaking it
|
|
199
|
+
// must turn the preset's suite RED. Each probe mutates ONE piece of the text agents actually read.
|
|
200
|
+
// `expect` is the number of times that anchor legitimately occurs (v3 declares each reply
|
|
201
|
+
// contract twice; v4/v5 document the formal contract in several prompt paths). The probe runner
|
|
202
|
+
// reports SETUP-FAIL when a count drifts, so this table is self-checking.
|
|
203
|
+
const DEFECT_CONTRACT_COUNT = { v2: 2, v3: 2, v4: 3, v5: 2 }
|
|
204
|
+
for (const [tag, pfx] of [['v2', 'vibe_math_'], ['v3', 'vibe_math_'], ['v4', 'vibe_v4_'], ['v5', 'vibe_v5_']]) {
|
|
205
|
+
probes.push(
|
|
206
|
+
{ name: tag + '-fidelity-defect-rule-removed', preset: tag, expect: 1,
|
|
207
|
+
guarantee: 'a faithfulness defect must NEVER be expressed as a vote of 0 (= 命题为假); it is a formalisation defect, not a refutation',
|
|
208
|
+
from: '发现任何偏差,不要投 0', to: '发现任何偏离一律投 0' },
|
|
209
|
+
{ name: tag + '-abbreviated-tool-name-injected', preset: tag, expect: 1,
|
|
210
|
+
guarantee: 'injected text must use the REGISTERED tool name (an abbreviated lean_archive is not a tool: the agent calls nothing)',
|
|
211
|
+
from: '· ' + pfx + 'lean_archive(归档)', to: '· lean_archive(归档)' },
|
|
212
|
+
{ name: tag + '-require-wording-removed', preset: tag, expect: 1,
|
|
213
|
+
guarantee: "the require gate's own wording (mandatory formalisation + the formal-required reason code) must reach the voter",
|
|
214
|
+
from: '**本模式要求**:必须产出 Lean 形式化', to: '**本模式要求**:可以不做形式化' },
|
|
215
|
+
{ name: tag + '-defect-decision-not-offered', preset: tag, expect: DEFECT_CONTRACT_COUNT[tag],
|
|
216
|
+
guarantee: 'the reply contract must offer decision=defect (without it a faithfulness defect cannot be recorded at all)',
|
|
217
|
+
from: '"decision":"used|blocked|defect"', to: '"decision":"used|blocked"' },
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
|
|
194
221
|
let ok = 0, bad = 0
|
|
195
222
|
console.log('-- Lean formal-verification sensitivity probes --')
|
|
196
223
|
console.log('(a probe passes when breaking the guarantee turns that preset\'s suite RED)')
|
|
197
224
|
console.log('')
|
|
198
225
|
|
|
199
|
-
|
|
226
|
+
// ── timing feedback: per-probe durations so the next run's strategy comes from data ──────
|
|
227
|
+
const CONCURRENCY = (() => {
|
|
228
|
+
const arg = process.argv.find((a) => a.startsWith('--concurrency='))
|
|
229
|
+
const env = process.env.PROBE_CONCURRENCY
|
|
230
|
+
const v = Number((arg && arg.split('=')[1]) || env || Math.min(4, cpus().length))
|
|
231
|
+
return Math.max(1, Number.isFinite(v) ? v : 1)
|
|
232
|
+
})()
|
|
233
|
+
const ONLY = (() => {
|
|
234
|
+
const eq = process.argv.find((a) => a.startsWith('--only='))
|
|
235
|
+
if (eq) return eq.split('=')[1]
|
|
236
|
+
// also accept the space form (`--only v5`), which the usage line advertises
|
|
237
|
+
const i = process.argv.indexOf('--only')
|
|
238
|
+
return i >= 0 && process.argv[i + 1] && !process.argv[i + 1].startsWith('--') ? process.argv[i + 1] : ''
|
|
239
|
+
})()
|
|
240
|
+
const selected = probes.filter((p) => !ONLY || p.name.includes(ONLY) || p.preset === ONLY)
|
|
241
|
+
if (process.argv.includes('--list')) {
|
|
242
|
+
for (const p of selected) console.log(p.preset + ' ' + p.name)
|
|
243
|
+
process.exit(0)
|
|
244
|
+
}
|
|
245
|
+
// A filter that matches nothing must FAIL, not report success: with zero probes the summary below
|
|
246
|
+
// would say "0 problems / ALL PROBES RED" — a textbook false green (AUDIT-CHECKLIST §2.5).
|
|
247
|
+
if (selected.length === 0) {
|
|
248
|
+
console.error('no probes matched' + (ONLY ? ' --only=' + ONLY : '') + ' — refusing to report success on an empty run')
|
|
249
|
+
process.exit(2)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function runAsync(cmd, args, opts) {
|
|
253
|
+
return new Promise((resolve) => {
|
|
254
|
+
const child = spawn(cmd, args, opts)
|
|
255
|
+
let out = '', err = ''
|
|
256
|
+
child.stdout.on('data', (d) => { out += d.toString() })
|
|
257
|
+
child.stderr.on('data', (d) => { err += d.toString() })
|
|
258
|
+
child.on('error', (e) => resolve({ status: null, error: e, stdout: out, stderr: err }))
|
|
259
|
+
child.on('close', (status) => resolve({ status, stdout: out, stderr: err }))
|
|
260
|
+
})
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// One probe = one targeted mutation + one run of that preset's suite. Returns a verdict object;
|
|
264
|
+
// never throws, so a single bad probe cannot take the pool down.
|
|
265
|
+
async function runProbe(p) {
|
|
266
|
+
const t0 = Date.now()
|
|
200
267
|
const preset = PLUGINS[p.preset]
|
|
201
268
|
const original = ORIGINAL[p.preset]
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
continue
|
|
206
|
-
}
|
|
269
|
+
const done = (kind, detail) => ({ p, kind, detail, ms: Date.now() - t0 })
|
|
270
|
+
if (p.from.startsWith('PLACEHOLDER_')) return done('setup', 'anchor not filled in yet')
|
|
271
|
+
const want = p.expect === undefined ? 1 : p.expect
|
|
207
272
|
const occurrences = original.split(p.from).length - 1
|
|
208
|
-
if (occurrences !==
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const mutated = original.replace(p.from, p.to)
|
|
214
|
-
|
|
273
|
+
if (occurrences !== want) return done('setup', 'anchor matched ' + occurrences + ' times (need exactly ' + want + ')')
|
|
274
|
+
// Mutate EVERY occurrence the anchor was asserted to have. `replace()` would only hit the first
|
|
275
|
+
// one, which silently produced a fake blind spot: the v5 reply contract is emitted in two places
|
|
276
|
+
// (replySpec + the voting prompt), so replacing just one left the other intact and the suite —
|
|
277
|
+
// correctly — stayed green.
|
|
278
|
+
const mutated = want > 1 ? original.split(p.from).join(p.to) : original.replace(p.from, p.to)
|
|
279
|
+
// One directory per probe: the mutated copy AND its corpus output (several suites write a
|
|
280
|
+
// corpus, and concurrent runs of the same suite must not race on that file).
|
|
281
|
+
const pdir = join(dir, p.name)
|
|
282
|
+
mkdirSync(pdir, { recursive: true })
|
|
283
|
+
const file = join(pdir, 'plugin.js')
|
|
215
284
|
writeFileSync(file, mutated, 'utf8')
|
|
216
|
-
|
|
217
285
|
// A mutation that does not even parse is red for the WRONG reason.
|
|
218
286
|
const chk = spawnSync(process.execPath, ['--check', file], { encoding: 'utf8' })
|
|
219
|
-
if (chk.status !== 0)
|
|
220
|
-
console.error(' SETUP-FAIL - ' + p.name + ': the mutated copy has a syntax error:\n' + String(chk.stderr || '').split('\n').slice(0, 4).join('\n'))
|
|
221
|
-
bad++
|
|
222
|
-
continue
|
|
223
|
-
}
|
|
224
|
-
|
|
287
|
+
if (chk.status !== 0) return done('setup', 'the mutated copy has a syntax error: ' + String(chk.stderr || '').split('\n').slice(0, 4).join(' '))
|
|
225
288
|
const env = Object.assign({}, process.env)
|
|
226
289
|
env[preset.env] = file
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
290
|
+
if (preset.corpusEnv) env[preset.corpusEnv] = join(pdir, 'corpus')
|
|
291
|
+
const r = await runAsync(process.execPath, [join(REPO, preset.suite)], { env, encoding: 'utf8', cwd: REPO })
|
|
292
|
+
if (r.status === null) return done('setup', 'the suite could not be started (' + String(r.error && r.error.message) + ')')
|
|
293
|
+
if (r.status !== 0) return done('ok', '')
|
|
294
|
+
return done('blind', '')
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const results = new Array(selected.length)
|
|
298
|
+
let cursor = 0
|
|
299
|
+
let finished = 0
|
|
300
|
+
const wall0 = Date.now()
|
|
301
|
+
async function worker() {
|
|
302
|
+
for (;;) {
|
|
303
|
+
const i = cursor++
|
|
304
|
+
if (i >= selected.length) return
|
|
305
|
+
const res = await runProbe(selected[i])
|
|
306
|
+
results[i] = res
|
|
307
|
+
finished++
|
|
308
|
+
const tag = '[' + String(finished).padStart(2) + '/' + selected.length + ']'
|
|
309
|
+
const secs = (res.ms / 1000).toFixed(1) + 's'
|
|
310
|
+
if (res.kind === 'ok') console.log(' ok - ' + res.p.name + ' [' + res.p.preset + '] => suite went RED as required (' + secs + ') [' + res.p.guarantee + ']')
|
|
311
|
+
else if (res.kind === 'blind') console.error(' BLIND SPOT ' + tag + ' - ' + res.p.name + ' [' + res.p.preset + '] (' + secs + ') => suite stayed GREEN, so it does NOT detect: ' + res.p.guarantee)
|
|
312
|
+
else console.error(' SETUP-FAIL ' + tag + ' - ' + res.p.name + ' [' + res.p.preset + '] (' + secs + '): ' + res.detail)
|
|
232
313
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
314
|
+
}
|
|
315
|
+
await Promise.all(Array.from({ length: Math.min(CONCURRENCY, selected.length) }, () => worker()))
|
|
316
|
+
|
|
317
|
+
// ── timing summary: this is the feedback that decides the next run's strategy ────────────
|
|
318
|
+
{
|
|
319
|
+
const wall = (Date.now() - wall0) / 1000
|
|
320
|
+
const sum = results.reduce((a, r) => a + (r ? r.ms : 0), 0) / 1000
|
|
321
|
+
const perPreset = {}
|
|
322
|
+
for (const r of results) {
|
|
323
|
+
if (!r) continue
|
|
324
|
+
perPreset[r.p.preset] = perPreset[r.p.preset] || { n: 0, s: 0 }
|
|
325
|
+
perPreset[r.p.preset].n++
|
|
326
|
+
perPreset[r.p.preset].s += r.ms / 1000
|
|
239
327
|
}
|
|
328
|
+
const slow = results.filter(Boolean).slice().sort((a, b) => b.ms - a.ms).slice(0, 5)
|
|
329
|
+
console.log('')
|
|
330
|
+
console.log('-- timing --')
|
|
331
|
+
console.log(' concurrency ' + CONCURRENCY + ' · wall ' + wall.toFixed(1) + 's · sum of probe times ' + sum.toFixed(1) + 's'
|
|
332
|
+
+ ' · speed-up x' + (sum / Math.max(wall, 0.001)).toFixed(2))
|
|
333
|
+
console.log(' per preset: ' + Object.keys(perPreset).sort().map((k) => k + ' ' + perPreset[k].n + ' probes/' + perPreset[k].s.toFixed(0) + 's').join(' · '))
|
|
334
|
+
console.log(' slowest: ' + slow.map((r) => r.p.name + ' ' + (r.ms / 1000).toFixed(1) + 's').join(' · '))
|
|
335
|
+
ok = results.filter((r) => r && r.kind === 'ok').length
|
|
336
|
+
bad = results.filter((r) => r && r.kind !== 'ok').length
|
|
240
337
|
}
|
|
241
338
|
|
|
242
|
-
rmSync(dir, { recursive: true, force: true })
|
|
243
|
-
console.log('')
|
|
244
339
|
console.log('formal sensitivity: ' + ok + ' probes detected the break, ' + bad + ' problems')
|
|
245
340
|
if (bad) process.exit(1)
|
|
246
341
|
console.log('ALL FORMAL PROBES RED AS REQUIRED')
|
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* PROMPT/INTERACTION INVARIANTS — the specific defect CLASSES this project has actually shipped,
|
|
4
|
+
* encoded as static invariants over all four presets. This is the mechanical answer to
|
|
5
|
+
* "are the prompt defects really fixed, and can they come back silently?".
|
|
6
|
+
*
|
|
7
|
+
* Every check below exists because the class was found in a real audit round:
|
|
8
|
+
* I1 abbreviated tool names in agent-facing text (lean_archive is not a registered tool)
|
|
9
|
+
* I2 a fidelity defect expressed as a 0 vote ("偏离 → 0" records 命题为假)
|
|
10
|
+
* I3 the defect rule missing from the injected text (不要投 0 + decision:'defect')
|
|
11
|
+
* I4 `defect` advertised but not handled by code (the v2 dead-channel class)
|
|
12
|
+
* I5 the reply contract not offering `defect` (a defect would be unrecordable)
|
|
13
|
+
* I6 a defect accepted without a reason (silent, unauditable decisions)
|
|
14
|
+
* I7 the wrong reply field name in the fidelity text (`verdict` where the parser reads `Result`)
|
|
15
|
+
* I8 the `formal` reply channel live in `off` mode (off must be a TRUE no-op)
|
|
16
|
+
* I9 corpus non-determinism / machine-path leaks / missing mode coverage
|
|
17
|
+
* I10 the prompt-rule sensitivity probes going missing (a guard that is not proven to go red)
|
|
18
|
+
* I11 the "no Lean toolchain" guidance naming only one of the two failure codes
|
|
19
|
+
* I12 the fidelity branch promising a hold that `encourage` cannot enforce
|
|
20
|
+
* I13 the Lean switch unreachable THROUGH the closed tool schema (v3 2.3.1: all four params
|
|
21
|
+
* missing from vibe_math_set_params, invisible to every suite because suites call handlers)
|
|
22
|
+
* I14 a parameter the tool schema advertises but the parameter layer silently drops
|
|
23
|
+
*
|
|
24
|
+
* Run: node audit-prompt-invariants.mjs (add --json for a machine-readable report)
|
|
25
|
+
* node audit-prompt-invariants.mjs --self-probe
|
|
26
|
+
* prove the guard is a guard: re-run itself on mutated sources and require the matching
|
|
27
|
+
* invariant to go RED (control run must stay green)
|
|
28
|
+
*/
|
|
29
|
+
import { readFileSync, existsSync } from 'node:fs'
|
|
30
|
+
import { spawnSync } from 'node:child_process'
|
|
31
|
+
import { fileURLToPath } from 'node:url'
|
|
32
|
+
import { join } from 'node:path'
|
|
33
|
+
|
|
34
|
+
const HERE = fileURLToPath(new URL('./', import.meta.url))
|
|
35
|
+
/**
|
|
36
|
+
* `PROMPT_INVARIANTS_MUTATE` carries a JSON `[rel, from, to]` triple: a single file is mutated IN
|
|
37
|
+
* MEMORY for one child run, so `--self-probe` can demonstrate that the invariant keyed to it really
|
|
38
|
+
* turns red. (Not a NUL-separated string: env values may not contain NUL bytes.)
|
|
39
|
+
*/
|
|
40
|
+
function readRaw(rel) {
|
|
41
|
+
const p = join(HERE, rel)
|
|
42
|
+
if (!existsSync(p)) return null
|
|
43
|
+
let text = readFileSync(p, 'utf8')
|
|
44
|
+
const mut = process.env.PROMPT_INVARIANTS_MUTATE
|
|
45
|
+
if (mut) {
|
|
46
|
+
try {
|
|
47
|
+
const [rel2, from, to] = JSON.parse(mut)
|
|
48
|
+
if (rel2 === rel && from) text = text.replace(from, to)
|
|
49
|
+
} catch (e) { /* a malformed mutation is a harness error, not an invariant failure */ }
|
|
50
|
+
}
|
|
51
|
+
return text
|
|
52
|
+
}
|
|
53
|
+
const read = readRaw
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Each mutation is a real defect shape from this project's history. `expect` is a substring that
|
|
57
|
+
* MUST appear in the failing run; `control: true` marks the unmutated run, which must stay green.
|
|
58
|
+
*/
|
|
59
|
+
const SELF_PROBE_MUTATIONS = [
|
|
60
|
+
{ name: 'control (no mutation)', rel: '', from: '', to: '', expect: '', control: true },
|
|
61
|
+
{
|
|
62
|
+
name: 'v3: one set_params registration loses the Lean params (I13 — the v2.3.1 shipped defect)',
|
|
63
|
+
rel: 'vibe-math-v3/vibe-math-v3.js',
|
|
64
|
+
from: 'formalVerify: { type: \'string\'',
|
|
65
|
+
to: 'formalVerifyDISABLED: { type: \'string\'',
|
|
66
|
+
expect: 'v3 I13: every vibe_math_set_params schema advertises',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'v3: objParams stops closing the schema (I13 premise)',
|
|
70
|
+
rel: 'vibe-math-v3/vibe-math-v3.js',
|
|
71
|
+
from: "additionalProperties: false, required: required || [] }",
|
|
72
|
+
to: 'required: required || [] }',
|
|
73
|
+
expect: 'v3 I13: every objParams definition closes tool schemas',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'v4: the schema advertises a knob the parameter layer drops (I14)',
|
|
77
|
+
rel: 'vibe-math-v4/vibe-math-v4.js',
|
|
78
|
+
from: "leanTimeoutMs:{type:'integer'}",
|
|
79
|
+
to: "leanTimeoutMs:{type:'integer'},bogusKnob:{type:'string'}",
|
|
80
|
+
expect: 'v4 I14: every key vibe_v4_set advertises is actually accepted',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: 'v5: normalizeParams stops accepting an advertised key (I14)',
|
|
84
|
+
rel: 'vibe-math-v5/vibe-math-v5.js',
|
|
85
|
+
from: "'meetingKeepEvery', 'leanTimeoutMs']",
|
|
86
|
+
to: "'meetingKeepEvery']",
|
|
87
|
+
expect: 'advertised but dropped: [leanTimeoutMs]',
|
|
88
|
+
},
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
if (process.argv.includes('--self-probe')) {
|
|
92
|
+
const bad = []
|
|
93
|
+
for (const mut of SELF_PROBE_MUTATIONS) {
|
|
94
|
+
const r = spawnSync(process.execPath, [fileURLToPath(import.meta.url), '--json'], {
|
|
95
|
+
cwd: HERE,
|
|
96
|
+
env: Object.assign({}, process.env, mut.control ? {} : { PROMPT_INVARIANTS_MUTATE: JSON.stringify([mut.rel, mut.from, mut.to]) }),
|
|
97
|
+
encoding: 'utf8',
|
|
98
|
+
})
|
|
99
|
+
let parsed = null
|
|
100
|
+
try { parsed = JSON.parse(r.stdout) } catch (e) { /* fall through to the diagnostic below */ }
|
|
101
|
+
const text = (r.stdout || '') + (r.stderr || '')
|
|
102
|
+
if (mut.control) {
|
|
103
|
+
const ok = r.status === 0 && parsed && parsed.failed === 0
|
|
104
|
+
console.log((ok ? 'PASS ' : 'FAIL ') + 'control: the unmutated run stays green (' + (parsed ? parsed.failed + ' failures' : 'unparsable output') + ')')
|
|
105
|
+
if (!ok) bad.push('control run was not green')
|
|
106
|
+
continue
|
|
107
|
+
}
|
|
108
|
+
const hit = text.includes(mut.expect)
|
|
109
|
+
const red = r.status === 1 && parsed && parsed.failed > 0
|
|
110
|
+
const ok = red && hit
|
|
111
|
+
console.log((ok ? 'PASS ' : 'FAIL ') + mut.name + (ok ? '' : ' → exit=' + r.status + ' hit=' + hit))
|
|
112
|
+
if (!ok) bad.push(mut.name + ' (exit ' + r.status + ', expected ' + JSON.stringify(mut.expect) + ')')
|
|
113
|
+
}
|
|
114
|
+
console.log('')
|
|
115
|
+
console.log('PROMPT INVARIANT SELF-PROBE: ' + (SELF_PROBE_MUTATIONS.length - bad.length) + '/' + SELF_PROBE_MUTATIONS.length + ' as required')
|
|
116
|
+
for (const b of bad) console.error(' FAIL ' + b)
|
|
117
|
+
process.exit(bad.length === 0 ? 0 : 1)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Blank out comments (line + block) while preserving string/template literals, so invariants about
|
|
122
|
+
* "text shown to an agent" do not fire on a COMMENT that quotes an anti-pattern. A naive regex
|
|
123
|
+
* would both miss block comments and mangle strings containing `//` (URLs), so this walks the
|
|
124
|
+
* source as a tiny scanner. Newlines are preserved to keep any line-based diagnostics aligned.
|
|
125
|
+
*/
|
|
126
|
+
function stripComments(src) {
|
|
127
|
+
const out = []
|
|
128
|
+
let i = 0
|
|
129
|
+
let state = 'code' // code | line | block | sq | dq | tpl
|
|
130
|
+
while (i < src.length) {
|
|
131
|
+
const c = src[i]
|
|
132
|
+
const c2 = src[i + 1]
|
|
133
|
+
if (state === 'code') {
|
|
134
|
+
if (c === '/' && c2 === '/') { state = 'line'; out.push(' '); i += 2; continue }
|
|
135
|
+
if (c === '/' && c2 === '*') { state = 'block'; out.push(' '); i += 2; continue }
|
|
136
|
+
if (c === "'") state = 'sq'
|
|
137
|
+
else if (c === '"') state = 'dq'
|
|
138
|
+
else if (c === '`') state = 'tpl'
|
|
139
|
+
out.push(c); i++; continue
|
|
140
|
+
}
|
|
141
|
+
if (state === 'line') {
|
|
142
|
+
if (c === '\n') { state = 'code'; out.push(c) } else out.push(' ')
|
|
143
|
+
i++; continue
|
|
144
|
+
}
|
|
145
|
+
if (state === 'block') {
|
|
146
|
+
if (c === '*' && c2 === '/') { state = 'code'; out.push(' '); i += 2; continue }
|
|
147
|
+
out.push(c === '\n' ? c : ' '); i++; continue
|
|
148
|
+
}
|
|
149
|
+
// inside a string/template: copy verbatim, honouring escapes and the closing quote
|
|
150
|
+
if (c === '\\') { out.push(c, c2 === undefined ? '' : c2); i += 2; continue }
|
|
151
|
+
if ((state === 'sq' && c === "'") || (state === 'dq' && c === '"') || (state === 'tpl' && c === '`')) state = 'code'
|
|
152
|
+
out.push(c); i++
|
|
153
|
+
}
|
|
154
|
+
return out.join('')
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Balanced-bracket slice starting at src[openIdx] (one of ( [ {), string/comment aware.
|
|
159
|
+
* Used by the TOOL-SURFACE invariants (I13/I14) to read a real parameter schema out of the source.
|
|
160
|
+
*/
|
|
161
|
+
function balanced(src, openIdx) {
|
|
162
|
+
let depth = 0
|
|
163
|
+
let i = openIdx
|
|
164
|
+
let state = 'code'
|
|
165
|
+
while (i < src.length) {
|
|
166
|
+
const c = src[i]
|
|
167
|
+
const c2 = src[i + 1]
|
|
168
|
+
if (state === 'code') {
|
|
169
|
+
if (c === "'" || c === '"' || c === '`') { state = c; i++; continue }
|
|
170
|
+
if (c === '(' || c === '[' || c === '{') depth++
|
|
171
|
+
else if (c === ')' || c === ']' || c === '}') { depth--; if (depth === 0) return src.slice(openIdx, i + 1) }
|
|
172
|
+
i++; continue
|
|
173
|
+
}
|
|
174
|
+
if (c === '\\') { i += 2; continue }
|
|
175
|
+
if (c === state) state = 'code'
|
|
176
|
+
i++
|
|
177
|
+
}
|
|
178
|
+
return src.slice(openIdx)
|
|
179
|
+
}
|
|
180
|
+
/** Split an object-body on TOP-LEVEL commas only (brackets and strings respected). */
|
|
181
|
+
function splitTopLevel(body) {
|
|
182
|
+
const parts = []
|
|
183
|
+
let cur = ''
|
|
184
|
+
let depth = 0
|
|
185
|
+
let state = 'code'
|
|
186
|
+
for (let i = 0; i < body.length; i++) {
|
|
187
|
+
const c = body[i]
|
|
188
|
+
const c2 = body[i + 1]
|
|
189
|
+
if (state === 'code') {
|
|
190
|
+
if (c === "'" || c === '"' || c === '`') { state = c; cur += c; continue }
|
|
191
|
+
if (c === '{' || c === '[' || c === '(') depth++
|
|
192
|
+
else if (c === '}' || c === ']' || c === ')') depth--
|
|
193
|
+
if (c === ',' && depth === 0) { parts.push(cur); cur = ''; continue }
|
|
194
|
+
cur += c; continue
|
|
195
|
+
}
|
|
196
|
+
if (c === '\\') { cur += c + (c2 || ''); i++; continue }
|
|
197
|
+
if (c === state) state = 'code'
|
|
198
|
+
cur += c
|
|
199
|
+
}
|
|
200
|
+
parts.push(cur)
|
|
201
|
+
return parts.map((p) => p.trim()).filter(Boolean)
|
|
202
|
+
}
|
|
203
|
+
/** Property keys of the object literal at/after `at` (null when there is no object literal there). */
|
|
204
|
+
function objectKeys(src, at) {
|
|
205
|
+
const open = src.indexOf('{', at)
|
|
206
|
+
if (open < 0) return null
|
|
207
|
+
const region = balanced(src, open)
|
|
208
|
+
return splitTopLevel(region.slice(1, -1))
|
|
209
|
+
.map((p) => { const m = p.match(/^['"]?([A-Za-z_$][\w$]*)['"]?\s*:/); return m ? m[1] : null })
|
|
210
|
+
.filter(Boolean)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const PRESETS = [
|
|
214
|
+
{ tag: 'v2', js: 'vibe-math-v2/vibe-math-v2.js', suite: 'formal-verify-v2.test.mjs', corpus: 'prompt-corpus-v2/formal-verify-v2.md', valueField: 'Result', prefix: 'vibe_math_', setTool: 'vibe_math_set_params' },
|
|
215
|
+
{ tag: 'v3', js: 'vibe-math-v3/vibe-math-v3.js', suite: 'formal-verify-v3.test.mjs', corpus: 'prompt-corpus-v3/formal-verify-v3.md', valueField: 'Result', prefix: 'vibe_math_', setTool: 'vibe_math_set_params' },
|
|
216
|
+
{ tag: 'v4', js: 'vibe-math-v4/vibe-math-v4.js', suite: 'formal-verify-v4.test.mjs', corpus: 'prompt-corpus-v4/formal-verify-v4.md', valueField: 'verdict', prefix: 'vibe_v4_', setTool: 'vibe_v4_set' },
|
|
217
|
+
{ tag: 'v5', js: 'vibe-math-v5/vibe-math-v5.js', suite: 'formal-verify-v5.test.mjs', corpus: 'prompt-corpus-v5/prompt-corpus-v5.md', valueField: 'verdict', prefix: 'vibe_v5_', setTool: 'vibe_v5_set' },
|
|
218
|
+
]
|
|
219
|
+
const LEAN_PARAMS = ['formalVerify', 'leanCommand', 'leanArgs', 'leanTimeoutMs']
|
|
220
|
+
|
|
221
|
+
let passed = 0
|
|
222
|
+
const failures = []
|
|
223
|
+
const notes = []
|
|
224
|
+
function check(cond, label, detail) {
|
|
225
|
+
if (cond) { passed++; return true }
|
|
226
|
+
failures.push(label + (detail ? ' — ' + detail : ''))
|
|
227
|
+
return false
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
for (const P of PRESETS) {
|
|
231
|
+
const js = read(P.js)
|
|
232
|
+
const suite = read(P.suite)
|
|
233
|
+
const corpus = read(P.corpus)
|
|
234
|
+
if (!check(js !== null, P.tag + ': plugin source readable', P.js)) continue
|
|
235
|
+
if (!check(suite !== null, P.tag + ': suite readable', P.suite)) continue
|
|
236
|
+
if (!check(corpus !== null, P.tag + ': prompt corpus shipped', P.corpus)) continue
|
|
237
|
+
|
|
238
|
+
// I1/I2 run on the source with comments blanked: a comment may legitimately quote an
|
|
239
|
+
// anti-pattern as documentation, but any STRING can reach an agent.
|
|
240
|
+
const code = stripComments(js)
|
|
241
|
+
|
|
242
|
+
// I1 — no abbreviated tool name in code/strings (code identifiers are leanArchive / leanRunTool,
|
|
243
|
+
// so a bare lean_* token is always a string that can be shown to an agent).
|
|
244
|
+
const bare = code.match(/(^|[^A-Za-z0-9_])lean_(run|archive|lib)\b/g) || []
|
|
245
|
+
check(bare.length === 0, P.tag + ' I1: no abbreviated Lean tool name in agent-facing text', 'found ' + JSON.stringify(bare.slice(0, 3)))
|
|
246
|
+
|
|
247
|
+
// I2 — never tell a voter to answer 0 for a faithfulness defect (comments excluded).
|
|
248
|
+
check(!/偏离\s*(?:→|->|=>)\s*0/.test(code), P.tag + ' I2: no "偏离 → 0" instruction')
|
|
249
|
+
|
|
250
|
+
// I3 — the defect rule is in the injected text.
|
|
251
|
+
check(js.includes('不要投 0'), P.tag + ' I3: injected text forbids a 0 vote on a defect')
|
|
252
|
+
check(/'defect'/.test(js) || /"defect"/.test(js), P.tag + ' I3: injected text names decision=\'defect\'')
|
|
253
|
+
|
|
254
|
+
// I4 — the defect decision is actually HANDLED (comparison + a downgrade to `attempted`).
|
|
255
|
+
const comparesDefect = /(?:===|==)\s*'defect'/.test(js) || /'defect'\s*(?:===|==)/.test(js)
|
|
256
|
+
check(comparesDefect, P.tag + ' I4: the code compares decision against \'defect\'')
|
|
257
|
+
const downgrades = /status:\s*'attempted'/.test(js) || /status='attempted'/.test(js) || /status:\s*"attempted"/.test(js)
|
|
258
|
+
check(downgrades, P.tag + " I4: a defect downgrades the record to 'attempted'")
|
|
259
|
+
|
|
260
|
+
// I5 — the reply contract offers the defect decision.
|
|
261
|
+
const contractCount = js.split('"decision":"used|blocked|defect"').length - 1
|
|
262
|
+
check(contractCount >= 1, P.tag + ' I5: the reply contract offers used|blocked|defect', 'occurrences=' + contractCount)
|
|
263
|
+
|
|
264
|
+
// I6 — a defect without a reason is refused.
|
|
265
|
+
check(/!note/.test(js), P.tag + ' I6: a defect/blocker without a note is rejected')
|
|
266
|
+
|
|
267
|
+
// I7 — the fidelity instruction names the field the parser really reads.
|
|
268
|
+
{
|
|
269
|
+
const lines = js.split(/\r?\n/)
|
|
270
|
+
const i = lines.findIndex((l) => l.includes('不要投 0'))
|
|
271
|
+
const window = i >= 0 ? lines.slice(Math.max(0, i - 3), i + 8).join('\n') : ''
|
|
272
|
+
check(i >= 0 && window.includes(P.valueField),
|
|
273
|
+
P.tag + ' I7: the fidelity instruction names ' + P.valueField + ' (the real reply field)',
|
|
274
|
+
i < 0 ? 'the 不要投 0 rule was not found' : 'window: ' + window.slice(0, 120).replace(/\n/g, ' | '))
|
|
275
|
+
if (P.tag === 'v2' || P.tag === 'v3') {
|
|
276
|
+
check(!/给出\s*verdict/.test(js), P.tag + ' I7b: no "给出 verdict" in a Result-based preset')
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// I8 — the `formal` reply channel is inert in off mode (tools stay usable on purpose).
|
|
281
|
+
const offGuards = {
|
|
282
|
+
v2: /absorbFormal(?:From)?Reply[\s\S]{0,900}!formalOn\(\)/,
|
|
283
|
+
v3: /absorbFormal(?:From)?Reply[\s\S]{0,900}!formalOn\(\)/,
|
|
284
|
+
v4: /applyFormalReply[\s\S]{0,900}!formalOn\(\)/,
|
|
285
|
+
v5: /formalOn\(\)\s*&&\s*p\.formal/,
|
|
286
|
+
}
|
|
287
|
+
check(offGuards[P.tag].test(js), P.tag + ' I8: the reply channel is gated on formalOn() (off stays a no-op)')
|
|
288
|
+
|
|
289
|
+
// I9 — the corpus covers every mode and is deterministic / machine-path free.
|
|
290
|
+
check(corpus.includes('【Lean 形式化验证(鼓励模式)】'), P.tag + ' I9: corpus covers encourage mode')
|
|
291
|
+
check(corpus.includes('【Lean 形式化验证(强制模式)】'), P.tag + ' I9: corpus covers REQUIRE mode')
|
|
292
|
+
check(corpus.includes('不要投 0'), P.tag + ' I9: corpus contains the fidelity/defect rule')
|
|
293
|
+
check(/used\|blocked\|defect/.test(corpus), P.tag + ' I9: corpus contains the reply contract line')
|
|
294
|
+
check(/【顺手形式化/.test(corpus), P.tag + ' I9: corpus contains the work-round line')
|
|
295
|
+
check(!/[A-Za-z]:[\\/]/.test(corpus), P.tag + ' I9: corpus leaks no absolute path')
|
|
296
|
+
check(!/\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}/.test(corpus), P.tag + ' I9: corpus carries no timestamp (deterministic)')
|
|
297
|
+
check(!/vibe-v[0-9]-[a-z]+-[A-Za-z0-9]{4,}/.test(corpus), P.tag + ' I9: corpus leaks no temp-dir name')
|
|
298
|
+
|
|
299
|
+
// I10 — the prompt-rule probes exist for this preset (a guard nobody can prove is a guard nobody has).
|
|
300
|
+
const probeSrc = read('audit-formal-sensitivity.mjs') || ''
|
|
301
|
+
for (const kind of ['fidelity-defect-rule-removed', 'abbreviated-tool-name-injected', 'require-wording-removed', 'defect-decision-not-offered']) {
|
|
302
|
+
check(probeSrc.includes("tag + '-" + kind + "'") || probeSrc.includes("'" + P.tag + '-' + kind + "'"),
|
|
303
|
+
P.tag + ' I10: probe exists for ' + kind)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// I10b — the suite asserts the defect path (behaviourally, not just wording).
|
|
307
|
+
check(/\bdefect\b/.test(suite), P.tag + ' I10b: the suite exercises the defect path')
|
|
308
|
+
|
|
309
|
+
// I11 — the "no toolchain" guidance must name BOTH failure codes. An agent that only knows
|
|
310
|
+
// LEAN_NOT_FOUND treats NO_SUBPROCESS as an unknown failure and retries instead of recording the
|
|
311
|
+
// blocker (contract §6 hard rule 4).
|
|
312
|
+
{
|
|
313
|
+
const lines = js.split(/\r?\n/)
|
|
314
|
+
const gi = lines.findIndex((l) => l.includes('宿主无 Lean 工具链'))
|
|
315
|
+
const win = gi >= 0 ? lines.slice(Math.max(0, gi - 3), gi + 1).join('\n') : ''
|
|
316
|
+
check(gi >= 0 && /LEAN_NOT_FOUND/.test(win) && /NO_SUBPROCESS/.test(win),
|
|
317
|
+
P.tag + ' I11: the no-toolchain guidance names LEAN_NOT_FOUND AND NO_SUBPROCESS',
|
|
318
|
+
gi < 0 ? 'the guidance line was not found' : 'window: ' + win.slice(0, 140).replace(/\n/g, ' | '))
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// I12 — the fidelity branch must qualify its promise BY MODE. Only `require` has a gate, so the
|
|
322
|
+
// text must say "本次裁定不定论" for require AND explicitly tell the voter, for encourage, that
|
|
323
|
+
// this mode has no gate and their abstention is what prevents a conclusion. Shipping the
|
|
324
|
+
// unconditional claim was a real defect that survived in three presets after v5 was fixed.
|
|
325
|
+
check(js.includes('本档没有门禁'), P.tag + ' I12: the fidelity text states the encourage branch has no gate')
|
|
326
|
+
check(js.includes('本次裁定**不定论**') || js.includes('本次裁定不定论'), P.tag + ' I12: the fidelity text states the require hold')
|
|
327
|
+
|
|
328
|
+
// I13 — the Lean switch must be REACHABLE THROUGH THE TOOL SCHEMA. Every tool schema here is
|
|
329
|
+
// built by `objParams`, which closes it with `additionalProperties:false`: a key the schema does
|
|
330
|
+
// not list is REJECTED by any schema-validating provider. v3 shipped 2.3.0/2.3.1 with all four
|
|
331
|
+
// Lean params missing from `vibe_math_set_params` and every suite stayed green, because the
|
|
332
|
+
// suites call the handler directly and never look at the schema — the feature could not be turned
|
|
333
|
+
// on at all. So: EVERY registration of the parameter tool (v2/v3 register it twice, for two agent
|
|
334
|
+
// scopes) must advertise all four, and the closed-schema premise must still hold.
|
|
335
|
+
{
|
|
336
|
+
// EVERY objParams definition must close its schema: one open definition (v2/v3 define it twice,
|
|
337
|
+
// for two agent scopes) would let tools registered through it accept arbitrary keys.
|
|
338
|
+
const defs = [...code.matchAll(/function objParams\(/g)].map((m) => m.index)
|
|
339
|
+
const closedDefs = defs.filter((i) => /additionalProperties:\s*false/.test(code.slice(i, i + 220)))
|
|
340
|
+
check(defs.length > 0 && closedDefs.length === defs.length,
|
|
341
|
+
P.tag + ' I13: every objParams definition closes tool schemas (additionalProperties:false)',
|
|
342
|
+
'definitions=' + defs.length + ' closed=' + closedDefs.length +
|
|
343
|
+
(defs.length ? '; if this is gone the schema no longer rejects unlisted keys and I13 loses its premise' : ''))
|
|
344
|
+
const regRe = new RegExp("registerTool\\(\\s*['\"]" + P.setTool + "['\"]", 'g')
|
|
345
|
+
const schemas = []
|
|
346
|
+
let m
|
|
347
|
+
while ((m = regRe.exec(code))) {
|
|
348
|
+
const rest = code.slice(m.index)
|
|
349
|
+
const oi = rest.indexOf('objParams(')
|
|
350
|
+
schemas.push(oi < 0 ? null : objectKeys(rest, oi + 'objParams'.length))
|
|
351
|
+
}
|
|
352
|
+
check(schemas.length >= 1, P.tag + ' I13: the parameter tool ' + P.setTool + ' is registered',
|
|
353
|
+
'no registerTool(\'' + P.setTool + '\') call found')
|
|
354
|
+
const bad = schemas.map((s, i) => (s === null ? 'reg#' + i + ': no objParams schema'
|
|
355
|
+
: LEAN_PARAMS.filter((k) => !s.includes(k)))).filter((x) => (Array.isArray(x) ? x.length : true))
|
|
356
|
+
check(schemas.length >= 1 && bad.length === 0,
|
|
357
|
+
P.tag + ' I13: every ' + P.setTool + ' schema advertises ' + LEAN_PARAMS.join('/'),
|
|
358
|
+
bad.length ? JSON.stringify(bad) : 'no registration found')
|
|
359
|
+
|
|
360
|
+
// I14 — a key the schema ACCEPTS must really be accepted by the parameter layer. Otherwise the
|
|
361
|
+
// tool advertises a knob that is silently dropped: the caller sees {ok:true} and nothing changes.
|
|
362
|
+
// The accept gate is DEFAULT_PARAMS for v2/v3/v4 (`if (k in params)`) and the typed lists inside
|
|
363
|
+
// normalizeParams for v5 (only those keys are copied through).
|
|
364
|
+
let accepts = null
|
|
365
|
+
if (P.tag === 'v5') {
|
|
366
|
+
const fn = code.indexOf('function normalizeParams')
|
|
367
|
+
const region = fn < 0 ? '' : balanced(code, code.indexOf('{', fn))
|
|
368
|
+
const names = []
|
|
369
|
+
for (const kind of ['ints', 'bools', 'strs', 'arrs']) {
|
|
370
|
+
const ai = region.indexOf('const ' + kind + ' = [')
|
|
371
|
+
if (ai < 0) continue
|
|
372
|
+
const arr = balanced(region, region.indexOf('[', ai))
|
|
373
|
+
for (const lit of arr.match(/'[A-Za-z_$][\w$]*'/g) || []) names.push(lit.slice(1, -1))
|
|
374
|
+
}
|
|
375
|
+
accepts = names.length ? [...new Set(names)] : null
|
|
376
|
+
} else {
|
|
377
|
+
const di = code.indexOf('DEFAULT_PARAMS =')
|
|
378
|
+
accepts = di < 0 ? null : objectKeys(code, di)
|
|
379
|
+
}
|
|
380
|
+
check(accepts !== null && accepts.length > 0, P.tag + ' I14: the parameter accept-set is readable',
|
|
381
|
+
'extractor found no parameter set — the invariant cannot be checked')
|
|
382
|
+
const union = [...new Set(schemas.filter(Boolean).flat())]
|
|
383
|
+
const dropped = accepts ? union.filter((k) => !accepts.includes(k)) : []
|
|
384
|
+
check(accepts !== null && dropped.length === 0,
|
|
385
|
+
P.tag + ' I14: every key ' + P.setTool + ' advertises is actually accepted (no silently-dropped knob)',
|
|
386
|
+
'advertised but dropped: [' + dropped.join(',') + ']')
|
|
387
|
+
check(union.length >= LEAN_PARAMS.length, P.tag + ' I14: the parameter schema was parsed (' + union.length + ' keys)',
|
|
388
|
+
'schema extraction returned ' + union.length + ' keys')
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
notes.push(P.tag + ': plugin ' + js.length + 'B · suite ' + suite.length + 'B · corpus ' + corpus.length + 'B')
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// Cross-preset: the probe script must refuse to report success on an empty selection (false green).
|
|
395
|
+
{
|
|
396
|
+
const probeSrc = read('audit-formal-sensitivity.mjs') || ''
|
|
397
|
+
check(/selected\.length === 0/.test(probeSrc), 'X1: the probe runner fails on an empty selection instead of reporting success')
|
|
398
|
+
const runner = read('run-tests.mjs') || ''
|
|
399
|
+
check(/no suites matched/.test(runner), 'X2: the suite runner fails when no suite matches')
|
|
400
|
+
check(/argv\[i \+ 1\]/.test(runner) && /argv\[\+\+i\]/.test(runner), 'X3: the suite runner accepts both --flag=x and --flag x')
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
const out = { passed, failed: failures.length, failures, notes }
|
|
404
|
+
if (process.argv.includes('--json')) {
|
|
405
|
+
console.log(JSON.stringify(out, null, 2))
|
|
406
|
+
} else {
|
|
407
|
+
console.log('-- prompt/interaction invariants (all four presets) --')
|
|
408
|
+
for (const n of notes) console.log(' note ' + n)
|
|
409
|
+
console.log('')
|
|
410
|
+
for (const f of failures) console.error(' FAIL ' + f)
|
|
411
|
+
console.log('')
|
|
412
|
+
console.log('PROMPT INVARIANTS: ' + passed + ' passed, ' + failures.length + ' failed')
|
|
413
|
+
}
|
|
414
|
+
process.exit(failures.length === 0 ? 0 : 1)
|