progmune-runtime 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mcp.json +11 -0
- package/.progmune_allowlist +50 -0
- package/.test_report/test_report.md +87 -0
- package/Dockerfile +2 -10
- package/FAQ.md +167 -0
- package/demo-project/auth.ts +55 -0
- package/demo-project/tsconfig.json +8 -0
- package/dist/ab-stats.js +11 -0
- package/dist/acl-breakdown.js +13 -0
- package/dist/all-sessions.js +11 -0
- package/dist/antibody-stats.js +11 -0
- package/dist/audit.js +218 -0
- package/dist/benchmark-count.js +7 -0
- package/dist/benchmark-full.js +17 -0
- package/dist/benchmark-pass-rate.js +54 -0
- package/dist/benchmark-report.js +67 -0
- package/dist/benchmark-save.js +62 -0
- package/dist/benchmark-status.js +15 -0
- package/dist/branch-ledger.js +365 -0
- package/dist/branch-tree-count.js +14 -0
- package/dist/check.js +506 -0
- package/dist/common-fixpath.js +12 -0
- package/dist/constraint-types.js +12 -0
- package/dist/deterministic-replay.js +277 -0
- package/dist/emitter.js +112 -12
- package/dist/exec-metrics.js +11 -0
- package/dist/execute.js +242 -0
- package/dist/extract-ir.js +550 -5
- package/dist/failure-collector.js +143 -0
- package/dist/failure-corpus.js +481 -35
- package/dist/failure-report.js +11 -0
- package/dist/failures.js +11 -0
- package/dist/fast-path-hits.js +13 -0
- package/dist/feedback.js +6 -3
- package/dist/file-lock.js +82 -0
- package/dist/find-session.js +10 -0
- package/dist/fingerprint-list.js +15 -0
- package/dist/gen-history-log.js +13 -0
- package/dist/generate.js +2 -1
- package/dist/generate_500.js +4 -2
- package/dist/genome.js +11 -0
- package/dist/heatmap-data.js +11 -0
- package/dist/heatmap.js +11 -0
- package/dist/immune-reporter.js +137 -0
- package/dist/learned.js +11 -0
- package/dist/ledger-registry.js +241 -0
- package/dist/llm.js +43 -2
- package/dist/load-benchmarks.js +47 -0
- package/dist/main.js +2 -1
- package/dist/mcp-server.mjs +446 -34
- package/dist/memory-layer.js +51 -13
- package/dist/metrics.js +11 -0
- package/dist/obs-web.js +561 -0
- package/dist/p0_ssg_demo.js +255 -40
- package/dist/planner.js +933 -65
- package/dist/protocol-registry.js +105 -0
- package/dist/recent-session.js +12 -0
- package/dist/repair-proposal.js +353 -0
- package/dist/report.js +32 -0
- package/dist/runtime-invariants.js +161 -0
- package/dist/runtime-types.js +117 -0
- package/dist/search-planner.js +38 -9
- package/dist/semantic-snapshot.js +155 -0
- package/dist/semantic-trace.js +1497 -0
- package/dist/semantic-validator.js +3 -2
- package/dist/semantic_guard_test.js +2 -1
- package/dist/sessions.js +11 -0
- package/dist/ssg-validator.js +658 -20
- package/dist/svl-distribution.js +11 -0
- package/dist/terminal-status.js +11 -0
- package/dist/test_failure_corpus.js +3 -1
- package/dist/token-savings.js +11 -0
- package/dist/total-repairs.js +12 -0
- package/dist/unresolved-count.js +12 -0
- package/dist/valid-fingerprints.js +13 -0
- package/dist/validator.js +116 -60
- package/dist/verify-fps.js +11 -0
- package/dist/verify-ledgers.js +11 -0
- package/docs/whitepaper-style.css +77 -0
- package/docs/whitepaper-v2.1.md +609 -0
- package/docs/whitepaper-v2.2.md +1064 -0
- package/docs/whitepaper-v2.2.pdf +0 -0
- package/fly.toml +1 -1
- package/package.json +13 -4
- package/protocols.json +136 -0
- package/public/dashboard.html +119 -0
- package/readme.md +829 -0
- package/server/hub.js +84 -12
- package/test/replay-golden/sess_1780063202050_mgeld.json +9 -0
- package/test/replay-golden/sess_1780064032560_gocld.json +354 -0
- package/test/replay-golden/sess_1780064413331_s2709.json +606 -0
- package/test/replay-golden/sess_1780064792710_y3avo.json +614 -0
- package/test/replay-golden.ts +84 -0
- package/test_benchmark.js +165 -0
- package/test_comprehensive.mjs +638 -0
- package/test_concurrency.js +129 -0
- package/test_ir_robustness.js +85 -0
- package/test_semantic_contracts.js +269 -0
- package/test_ssg_stress.js +156 -0
- package/test_svl3.js +58 -0
- package/tsconfig.json +1 -1
- package/.env.example +0 -3
- package/.progmune_memory/fingerprints.json +0 -7
- package/.progmune_memory/opt_in.json +0 -4
- package/README.md +0 -118
- package/dist/mcp-server.js +0 -55
- package/immune_hub_data/2026-05-14.json +0 -50
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 端到端基准测试
|
|
3
|
+
* ==============
|
|
4
|
+
* 测量约束引擎各环节的性能开销
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
|
|
10
|
+
const PROJECT_ROOT = '/Users/shenlian/progmune-runtime';
|
|
11
|
+
const results = { pass: 0, fail: 0, total: 0, details: [] };
|
|
12
|
+
|
|
13
|
+
function assert(condition, name, detail) {
|
|
14
|
+
results.total++;
|
|
15
|
+
if (condition) { results.pass++; results.details.push({ name, status: '✅', detail }); }
|
|
16
|
+
else { results.fail++; results.details.push({ name, status: '❌', detail }); }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
console.log('🧪 端到端基准测试\n');
|
|
20
|
+
|
|
21
|
+
// ============================================================
|
|
22
|
+
// 1. validateActionSequence 性能
|
|
23
|
+
// ============================================================
|
|
24
|
+
console.log('--- validateActionSequence 性能 ---');
|
|
25
|
+
|
|
26
|
+
// 构建 100 个函数的 IR
|
|
27
|
+
const ir = [];
|
|
28
|
+
for (let i = 0; i < 100; i++) {
|
|
29
|
+
ir.push({ name: `func_${i}`, params: [{ name: 'x', type: 'str' }], returnType: 'bool' });
|
|
30
|
+
}
|
|
31
|
+
fs.writeFileSync(path.join(PROJECT_ROOT, 'ir.json'), JSON.stringify(ir));
|
|
32
|
+
Object.keys(require.cache).filter(k => k.includes('validator')).forEach(k => delete require.cache[k]);
|
|
33
|
+
const { validateActionSequence } = require('./dist/validator.js');
|
|
34
|
+
|
|
35
|
+
// 1a. 合法动作序列(100 次调用)
|
|
36
|
+
const validActions = [];
|
|
37
|
+
for (let i = 0; i < 100; i++) {
|
|
38
|
+
validActions.push({ kind: 'call', function: `func_${i % 100}`, args: [{ name: 'x', type: 'str', value: 'test' }], assignTo: `r${i}` });
|
|
39
|
+
}
|
|
40
|
+
const start1 = Date.now();
|
|
41
|
+
const r1 = validateActionSequence(validActions);
|
|
42
|
+
const t1 = Date.now() - start1;
|
|
43
|
+
assert(r1.valid, '100 次合法调用通过', `${t1}ms`);
|
|
44
|
+
|
|
45
|
+
// 1b. 非法动作序列(100 次调用不存在的函数)
|
|
46
|
+
const invalidActions = [];
|
|
47
|
+
for (let i = 0; i < 100; i++) {
|
|
48
|
+
invalidActions.push({ kind: 'call', function: `no_such_func_${i}`, args: [] });
|
|
49
|
+
}
|
|
50
|
+
const start1b = Date.now();
|
|
51
|
+
const r1b = validateActionSequence(invalidActions);
|
|
52
|
+
const t1b = Date.now() - start1b;
|
|
53
|
+
assert(!r1b.valid && r1b.errors.length === 100, '100 次非法调用全部拦截', `${t1b}ms, ${r1b.errors.length} 个错误`);
|
|
54
|
+
|
|
55
|
+
// ============================================================
|
|
56
|
+
// 2. checkSemantic 性能
|
|
57
|
+
// ============================================================
|
|
58
|
+
console.log('\n--- checkSemantic 性能 ---');
|
|
59
|
+
|
|
60
|
+
const { checkSemantic } = require('./dist/semantic-validator.js');
|
|
61
|
+
|
|
62
|
+
const irWithContracts = [];
|
|
63
|
+
for (let i = 0; i < 50; i++) {
|
|
64
|
+
irWithContracts.push({
|
|
65
|
+
name: `secure_func_${i}`,
|
|
66
|
+
params: [{ name: 'input', type: 'str' }],
|
|
67
|
+
contracts: [
|
|
68
|
+
{ type: 'must_be_checked', description: '结果必须检查' },
|
|
69
|
+
{ type: 'sequence_after', function: `secure_func_${Math.max(0, i-1)}`, description: '必须顺序执行' }
|
|
70
|
+
]
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
fs.writeFileSync(path.join(PROJECT_ROOT, 'ir.json'), JSON.stringify(irWithContracts));
|
|
74
|
+
delete require.cache[require.resolve('./dist/semantic-validator.js')];
|
|
75
|
+
const { checkSemantic: check2 } = require('./dist/semantic-validator.js');
|
|
76
|
+
|
|
77
|
+
const semActions = [];
|
|
78
|
+
for (let i = 0; i < 50; i++) {
|
|
79
|
+
semActions.push({ kind: 'call', function: `secure_func_${i}`, args: [{ name: 'input', type: 'str', value: 'data' }], assignTo: `r${i}` });
|
|
80
|
+
}
|
|
81
|
+
// 全部没有 if 检查 → 全部违规
|
|
82
|
+
const start2 = Date.now();
|
|
83
|
+
const r2 = check2('benchmark', semActions);
|
|
84
|
+
const t2 = Date.now() - start2;
|
|
85
|
+
assert(!r2.valid && r2.errors.length >= 50, '50 个合约全部检测', `${t2}ms, ${r2.errors.length} 个违规`);
|
|
86
|
+
|
|
87
|
+
// ============================================================
|
|
88
|
+
// 3. SSG 状态机性能(1000 次跃迁)
|
|
89
|
+
// ============================================================
|
|
90
|
+
console.log('\n--- SSG 性能 ---');
|
|
91
|
+
|
|
92
|
+
const { StateMachineValidator } = require('./dist/ssg-validator.js');
|
|
93
|
+
|
|
94
|
+
const ssgProtocols = [];
|
|
95
|
+
for (let i = 0; i < 50; i++) {
|
|
96
|
+
ssgProtocols.push({
|
|
97
|
+
function: `step_${i}`,
|
|
98
|
+
protocol: { pre_states: [`S${i}`], post_states: [`S${i+1}`], invalidate: [`S${i}`] }
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
const ssv = new StateMachineValidator(ssgProtocols, 'S0');
|
|
102
|
+
const start3 = Date.now();
|
|
103
|
+
for (let i = 0; i < 50; i++) {
|
|
104
|
+
ssv.apply(`step_${i}`);
|
|
105
|
+
}
|
|
106
|
+
const t3 = Date.now() - start3;
|
|
107
|
+
assert(t3 < 100, 'SSG: 50 次跃迁耗时 < 100ms', `${t3}ms`);
|
|
108
|
+
|
|
109
|
+
// ============================================================
|
|
110
|
+
// 4. 完整 pipeline 模拟(IR → plan → emit)
|
|
111
|
+
// ============================================================
|
|
112
|
+
console.log('\n--- Pipeline 端到端 ---');
|
|
113
|
+
|
|
114
|
+
const { emitPython } = require('./dist/python-emitter.js');
|
|
115
|
+
|
|
116
|
+
const pipelineActions = [
|
|
117
|
+
{ kind: 'assign', target: 'email', value: '"user@example.com"' },
|
|
118
|
+
{ kind: 'call', function: 'validate_email', args: [{ name: 'email', type: 'str', value: 'email' }], assignTo: 'valid' },
|
|
119
|
+
{ kind: 'if', condition: 'valid', thenActions: [
|
|
120
|
+
{ kind: 'call', function: 'send_otp', args: [{ name: 'email', type: 'str', value: 'email' }], assignTo: 'sent' }
|
|
121
|
+
], elseActions: [
|
|
122
|
+
{ kind: 'return', value: '"invalid email"' }
|
|
123
|
+
]}
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
const start4 = Date.now();
|
|
127
|
+
const code = emitPython(pipelineActions);
|
|
128
|
+
const t4 = Date.now() - start4;
|
|
129
|
+
assert(code.length > 0 && code.includes('def main'), 'emitPython: 生成有效 Python 代码', `${t4}ms, ${code.length} 字符`);
|
|
130
|
+
|
|
131
|
+
// ============================================================
|
|
132
|
+
// 5. 内存使用(加载大 IR)
|
|
133
|
+
// ============================================================
|
|
134
|
+
console.log('\n--- 内存使用 ---');
|
|
135
|
+
|
|
136
|
+
const hugeIr = [];
|
|
137
|
+
for (let i = 0; i < 5000; i++) {
|
|
138
|
+
hugeIr.push({
|
|
139
|
+
name: `f_${i}`,
|
|
140
|
+
params: [{ name: 'p1', type: 'str' }, { name: 'p2', type: 'int' }],
|
|
141
|
+
returnType: 'dict',
|
|
142
|
+
file: 'huge.py'
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
fs.writeFileSync(path.join(PROJECT_ROOT, 'ir.json'), JSON.stringify(hugeIr));
|
|
146
|
+
Object.keys(require.cache).filter(k => k.includes('validator')).forEach(k => delete require.cache[k]);
|
|
147
|
+
const { validateActionSequence: v5 } = require('./dist/validator.js');
|
|
148
|
+
|
|
149
|
+
const start5 = Date.now();
|
|
150
|
+
const r5 = v5([{ kind: 'call', function: 'f_2500', args: [{ name: 'p1', type: 'str', value: 'x' }, { name: 'p2', type: 'int', value: '1' }] }]);
|
|
151
|
+
const t5 = Date.now() - start5;
|
|
152
|
+
assert(r5.valid && t5 < 200, '5000 函数 IR 中查找 < 200ms', `${t5}ms`);
|
|
153
|
+
|
|
154
|
+
// ============================================================
|
|
155
|
+
// 报告
|
|
156
|
+
// ============================================================
|
|
157
|
+
console.log('\n========================================');
|
|
158
|
+
console.log(`结果: ${results.pass}/${results.total} 通过`);
|
|
159
|
+
console.log('========================================\n');
|
|
160
|
+
|
|
161
|
+
results.details.forEach(d => console.log(` ${d.status} ${d.name}${d.detail ? ' (' + d.detail + ')' : ''}`));
|
|
162
|
+
|
|
163
|
+
const passRate = (results.pass / results.total * 100).toFixed(0);
|
|
164
|
+
console.log(`\n通过率: ${passRate}%`);
|
|
165
|
+
process.exit(results.fail > 0 ? 1 : 0);
|