pi-mega-compact 0.20.42 → 0.20.43
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/assets/vector-cortex/encoder-v1/manifest.json +1 -1
- package/dist/config/vector-cortex-enc0a.js +32 -0
- package/dist/config/vector-cortex.js +2 -2
- package/dist/config.js +1 -1
- package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +1 -0
- package/dist/src/config/vector-cortex-enc0a.js +32 -0
- package/dist/src/config/vector-cortex.js +2 -2
- package/dist/src/config.js +1 -1
- package/dist/src/vector-cortex/_acceptance-enc0a-contract.js +60 -0
- package/dist/src/vector-cortex/_acceptance-vc2a-conformance.js +90 -0
- package/dist/src/vector-cortex/_acceptance-vc2a-runtime.js +285 -0
- package/dist/src/vector-cortex/_acceptance-vc2b-conformance.js +92 -0
- package/dist/src/vector-cortex/_acceptance-vc2b-heads.js +221 -0
- package/dist/src/vector-cortex/encoder/asset.js +3 -2
- package/dist/src/vector-cortex/encoder/decision.js +75 -0
- package/dist/src/vector-cortex/encoder/types-vc2c.js +41 -0
- package/dist/src/vector-cortex/encoder/types.js +13 -34
- package/dist/vector-cortex/_acceptance-enc0a-contract.js +60 -0
- package/dist/vector-cortex/_acceptance-vc2a-conformance.js +90 -0
- package/dist/vector-cortex/_acceptance-vc2a-runtime.js +285 -0
- package/dist/vector-cortex/_acceptance-vc2b-conformance.js +92 -0
- package/dist/vector-cortex/_acceptance-vc2b-heads.js +221 -0
- package/dist/vector-cortex/encoder/asset.js +3 -2
- package/dist/vector-cortex/encoder/decision.js +75 -0
- package/dist/vector-cortex/encoder/types-vc2c.js +41 -0
- package/dist/vector-cortex/encoder/types.js +13 -34
- package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +6 -0
- package/package.json +1 -1
- package/src/config/vector-cortex-enc0a.ts +34 -0
- package/src/config/vector-cortex.ts +2 -2
- package/src/config.ts +1 -0
- package/src/vector-cortex/_acceptance-enc0a-contract.ts +71 -0
- package/src/vector-cortex/_acceptance-vc2a-conformance.ts +119 -0
- package/src/vector-cortex/_acceptance-vc2a-runtime.ts +300 -0
- package/src/vector-cortex/_acceptance-vc2b-conformance.ts +121 -0
- package/src/vector-cortex/_acceptance-vc2b-heads.ts +234 -0
- package/src/vector-cortex/encoder/asset.ts +3 -2
- package/src/vector-cortex/encoder/bench-export.ts +2 -2
- package/src/vector-cortex/encoder/decision.ts +125 -0
- package/src/vector-cortex/encoder/runtime-native.ts +1 -1
- package/src/vector-cortex/encoder/runtime-wasm.ts +1 -1
- package/src/vector-cortex/encoder/types-vc2c.ts +124 -0
- package/src/vector-cortex/encoder/types.ts +18 -115
|
@@ -1 +1 @@
|
|
|
1
|
-
{"batch":1,"heads":{"cacheStability":64,"contradiction":128,"dependency":128,"payloadRouting":32,"semantic":384},"hiddenWidth":384,"maxTokens":512,"modelVersion":"encoder-v1-placeholder","onnx":{"bytes":42,"path":"model.onnx","sha256":"01cbed8b0b301609542ff8c392c3e7d927b0d848ac53a768dfffd33bfe6005ff"},"opset":
|
|
1
|
+
{"batch":1,"heads":{"cacheStability":64,"contradiction":128,"dependency":128,"payloadRouting":32,"semantic":384},"hiddenWidth":384,"maxTokens":512,"modelVersion":"encoder-v1-placeholder","onnx":{"bytes":42,"path":"model.onnx","sha256":"01cbed8b0b301609542ff8c392c3e7d927b0d848ac53a768dfffd33bfe6005ff"},"opset":21,"platform":"linux-x64","schema":"model-manifest-v1","semanticWidth":384,"tokenizer":{"bytes":8518,"path":"tokenizer.json","sha256":"ada18e5c4dfcb5c369c05f4ffc10bc40298ce707e78f16135c6d33019f6db8cd"},"totalBytes":8560,"trainingManifestDigest":"e9b2550dbb79141af84440dda65ca21d3509904b2c09a89316145137a5b5e3de"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* config/vector-cortex-enc0a.ts — ENC-0a learned-encoder backend-decision flag.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from vector-cortex.ts so that file stays under the 300-line soft
|
|
5
|
+
* limit (soft-as-hard gate), exactly as vector-cortex-vc9a.ts..vector-cortex-vc9d.ts
|
|
6
|
+
* were. This is the first ENC (real learned encoder) sprint flag. vector-cortex.ts
|
|
7
|
+
* re-exports the ENUM below and root src/config.ts re-exports it, so no consumer
|
|
8
|
+
* import path changes.
|
|
9
|
+
*
|
|
10
|
+
* ENC-0a locks the runtime-backend choice (transformers.js/WASM vs
|
|
11
|
+
* onnxruntime-node native), the per-platform install-size matrix, the opset
|
|
12
|
+
* baseline (re-baselined 17 -> 21) and the license/pinning audit. It writes a
|
|
13
|
+
* durable decision record and bench JSON but touches neither the store schema
|
|
14
|
+
* nor stateDir tables (pure migration).
|
|
15
|
+
*
|
|
16
|
+
* The split is purely mechanical: ENC_0A_ENABLED is byte-identical in name,
|
|
17
|
+
* semantics, and default to the definition it replaces, and vector-cortex.ts
|
|
18
|
+
* re-exports it so every existing `from "./config/vector-cortex.js"` import
|
|
19
|
+
* keeps resolving unchanged.
|
|
20
|
+
*
|
|
21
|
+
* Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
|
|
22
|
+
*/
|
|
23
|
+
import { sprintFlag } from "./vector-cortex-flag.js";
|
|
24
|
+
/**
|
|
25
|
+
* ENC-0a — learned-encoder backend-decision lock. Default ON.
|
|
26
|
+
* `MEGACOMPACT_ENC_0A=0` disables and is byte-identical to the predecessor
|
|
27
|
+
* (placeholder encoder): no decision record is written and no newer
|
|
28
|
+
* backend-resolution script runs — the runtime keeps serving mode B trigram
|
|
29
|
+
* exactly as before. This flag MUST also be a dashboard SETTINGS toggle (visible
|
|
30
|
+
* in config UI, never in EXCLUDED_SETTINGS), mirroring VC4A..VC9D.
|
|
31
|
+
*/
|
|
32
|
+
export const ENC_0A_ENABLED = () => sprintFlag("MEGACOMPACT_ENC_0A");
|
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
* `=0`/`_DISABLED` off. Flag-OFF is byte-identical to the predecessor sprint's
|
|
6
6
|
* behavior (for VC0A: mode C — observer absent, zero evaluation writes).
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* them without re-declaring the ownership boundary. Pi-agnostic, dependency-free.
|
|
8
|
+
* Breaker/triad constants (TRIAD_RESILIENCE.md) live here; pi-agnostic, dep-free.
|
|
10
9
|
*/
|
|
11
10
|
import { sprintFlag } from "./vector-cortex-flag.js";
|
|
12
11
|
// VC0/VC1/VC2 foundation-phase flags in vector-cortex-early.ts; re-exported
|
|
@@ -251,5 +250,6 @@ export { ML5C_ENABLED } from "./vector-cortex-ml5c.js";
|
|
|
251
250
|
export { ML5D_ENABLED } from "./vector-cortex-ml5d.js";
|
|
252
251
|
export { ML5E_ENABLED } from "./vector-cortex-ml5e.js";
|
|
253
252
|
export { DEDUP_ATTR_ENABLED } from "./vector-cortex-dedup-attr.js";
|
|
253
|
+
export { ENC_0A_ENABLED } from "./vector-cortex-enc0a.js";
|
|
254
254
|
// Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
|
|
255
255
|
export { BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./vector-cortex-breakers.js";
|
package/dist/config.js
CHANGED
|
@@ -114,4 +114,4 @@ export const NEW_UI = () => ragEnabled("MEGACOMPACT_NEW_UI");
|
|
|
114
114
|
// default ON, `=0`/`_DISABLED` off. Re-exported from src/config/vector-cortex.ts
|
|
115
115
|
// so root consumers share one source of truth.
|
|
116
116
|
// ---------------------------------------------------------------------------
|
|
117
|
-
export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, VC6C_ENABLED, VC7A_ENABLED, VC7B_ENABLED, VC7C_ENABLED, VC8A_ENABLED, VC8B_ENABLED, VC8C_ENABLED, VC9A_ENABLED, VC9B_ENABLED, VC9C_ENABLED, VC9D_ENABLED, PCC_ENABLED, ML5A_ENABLED, ML5B_ENABLED, ML5C_ENABLED, ML5D_ENABLED, ML5E_ENABLED, DEDUP_ATTR_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
|
|
117
|
+
export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, VC6C_ENABLED, VC7A_ENABLED, VC7B_ENABLED, VC7C_ENABLED, VC8A_ENABLED, VC8B_ENABLED, VC8C_ENABLED, VC9A_ENABLED, VC9B_ENABLED, VC9C_ENABLED, VC9D_ENABLED, PCC_ENABLED, ML5A_ENABLED, ML5B_ENABLED, ML5C_ENABLED, ML5D_ENABLED, ML5E_ENABLED, DEDUP_ATTR_ENABLED, ENC_0A_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
|
|
@@ -58,5 +58,6 @@ export const VECTOR_CORTEX_SETTINGS = {
|
|
|
58
58
|
boolDirect("MEGACOMPACT_ML5_D", "ML5-D Dashboard Improve Cortex", "ML5-D dashboard 'Improve Cortex' surface: the ModelImprovementCard + POST /api/cortex/improve + GET /api/cortex/improve/status/:jobId. ON (default) = the card renders and Improve launches a local ML5-A training job. OFF = both improve endpoints return 404 and VectorCortexTab omits the card, byte-identical to ML5-C.", true),
|
|
59
59
|
boolDirect("MEGACOMPACT_ML5_E", "ML5-E Nightly Retraining Cron", "ML5-E nightly retraining + feedback loop: the user's own post-redaction conversation turns become fresh training signal, the five heads are re-fit nightly via system cron, calibration is re-validated, and mode-A promotion is re-checked without human intervention. The cron is system-configured (crontab -e); the extension never installs or writes a crontab. Candidates are written to ~/.pi/mega-compact-encoder/candidates/ and promoted via the ML5-D Improve Cortex flow. ON (default) = the scripts may be invoked by the system cron. OFF = scripts are never invoked; byte-identical to ML5-D.", true),
|
|
60
60
|
boolDirect("MEGACOMPACT_DEDUP_ATTR", "Dedup Tier Attribution Rollup", "Dedup tier-attribution rollup: per-tier dedup catch shares (L0/L1/L2/new percent of dedup decisions) read from the local events.log dedup_audit stream (GET /api/dedup-tier-attribution). OFF = 404 + no cache file, byte-identical predecessor.", true),
|
|
61
|
+
boolDirect("MEGACOMPACT_ENC_0A", "ENC-0a Encoder Backend Decision", "ENC-0a learned-encoder backend-decision lock: records the transformers.js/WASM vs onnxruntime-node choice, per-platform install matrix, opset-21 baseline and pinned digests in docs/vector-cortex/encoder-backend-decision.md. OFF = no decision record written / no resolver runs, mode B trigram byte-identical predecessor.", true),
|
|
61
62
|
],
|
|
62
63
|
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* config/vector-cortex-enc0a.ts — ENC-0a learned-encoder backend-decision flag.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from vector-cortex.ts so that file stays under the 300-line soft
|
|
5
|
+
* limit (soft-as-hard gate), exactly as vector-cortex-vc9a.ts..vector-cortex-vc9d.ts
|
|
6
|
+
* were. This is the first ENC (real learned encoder) sprint flag. vector-cortex.ts
|
|
7
|
+
* re-exports the ENUM below and root src/config.ts re-exports it, so no consumer
|
|
8
|
+
* import path changes.
|
|
9
|
+
*
|
|
10
|
+
* ENC-0a locks the runtime-backend choice (transformers.js/WASM vs
|
|
11
|
+
* onnxruntime-node native), the per-platform install-size matrix, the opset
|
|
12
|
+
* baseline (re-baselined 17 -> 21) and the license/pinning audit. It writes a
|
|
13
|
+
* durable decision record and bench JSON but touches neither the store schema
|
|
14
|
+
* nor stateDir tables (pure migration).
|
|
15
|
+
*
|
|
16
|
+
* The split is purely mechanical: ENC_0A_ENABLED is byte-identical in name,
|
|
17
|
+
* semantics, and default to the definition it replaces, and vector-cortex.ts
|
|
18
|
+
* re-exports it so every existing `from "./config/vector-cortex.js"` import
|
|
19
|
+
* keeps resolving unchanged.
|
|
20
|
+
*
|
|
21
|
+
* Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
|
|
22
|
+
*/
|
|
23
|
+
import { sprintFlag } from "./vector-cortex-flag.js";
|
|
24
|
+
/**
|
|
25
|
+
* ENC-0a — learned-encoder backend-decision lock. Default ON.
|
|
26
|
+
* `MEGACOMPACT_ENC_0A=0` disables and is byte-identical to the predecessor
|
|
27
|
+
* (placeholder encoder): no decision record is written and no newer
|
|
28
|
+
* backend-resolution script runs — the runtime keeps serving mode B trigram
|
|
29
|
+
* exactly as before. This flag MUST also be a dashboard SETTINGS toggle (visible
|
|
30
|
+
* in config UI, never in EXCLUDED_SETTINGS), mirroring VC4A..VC9D.
|
|
31
|
+
*/
|
|
32
|
+
export const ENC_0A_ENABLED = () => sprintFlag("MEGACOMPACT_ENC_0A");
|
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
* `=0`/`_DISABLED` off. Flag-OFF is byte-identical to the predecessor sprint's
|
|
6
6
|
* behavior (for VC0A: mode C — observer absent, zero evaluation writes).
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* them without re-declaring the ownership boundary. Pi-agnostic, dependency-free.
|
|
8
|
+
* Breaker/triad constants (TRIAD_RESILIENCE.md) live here; pi-agnostic, dep-free.
|
|
10
9
|
*/
|
|
11
10
|
import { sprintFlag } from "./vector-cortex-flag.js";
|
|
12
11
|
// VC0/VC1/VC2 foundation-phase flags in vector-cortex-early.ts; re-exported
|
|
@@ -251,5 +250,6 @@ export { ML5C_ENABLED } from "./vector-cortex-ml5c.js";
|
|
|
251
250
|
export { ML5D_ENABLED } from "./vector-cortex-ml5d.js";
|
|
252
251
|
export { ML5E_ENABLED } from "./vector-cortex-ml5e.js";
|
|
253
252
|
export { DEDUP_ATTR_ENABLED } from "./vector-cortex-dedup-attr.js";
|
|
253
|
+
export { ENC_0A_ENABLED } from "./vector-cortex-enc0a.js";
|
|
254
254
|
// Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
|
|
255
255
|
export { BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./vector-cortex-breakers.js";
|
package/dist/src/config.js
CHANGED
|
@@ -114,4 +114,4 @@ export const NEW_UI = () => ragEnabled("MEGACOMPACT_NEW_UI");
|
|
|
114
114
|
// default ON, `=0`/`_DISABLED` off. Re-exported from src/config/vector-cortex.ts
|
|
115
115
|
// so root consumers share one source of truth.
|
|
116
116
|
// ---------------------------------------------------------------------------
|
|
117
|
-
export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, VC6C_ENABLED, VC7A_ENABLED, VC7B_ENABLED, VC7C_ENABLED, VC8A_ENABLED, VC8B_ENABLED, VC8C_ENABLED, VC9A_ENABLED, VC9B_ENABLED, VC9C_ENABLED, VC9D_ENABLED, PCC_ENABLED, ML5A_ENABLED, ML5B_ENABLED, ML5C_ENABLED, ML5D_ENABLED, ML5E_ENABLED, DEDUP_ATTR_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
|
|
117
|
+
export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, VC6C_ENABLED, VC7A_ENABLED, VC7B_ENABLED, VC7C_ENABLED, VC8A_ENABLED, VC8B_ENABLED, VC8C_ENABLED, VC9A_ENABLED, VC9B_ENABLED, VC9C_ENABLED, VC9D_ENABLED, PCC_ENABLED, ML5A_ENABLED, ML5B_ENABLED, ML5C_ENABLED, ML5D_ENABLED, ML5E_ENABLED, DEDUP_ATTR_ENABLED, ENC_0A_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** ENC-0a buildDecision contract constructor suite — extracted from
|
|
2
|
+
* enc0a-acceptance.test.ts for soft-limit compliance. Receives the contract
|
|
3
|
+
* constructor + constants from the aggregator (no import cycle).
|
|
4
|
+
*/
|
|
5
|
+
import { test, describe } from "node:test";
|
|
6
|
+
import assert from "node:assert/strict";
|
|
7
|
+
export function registerEnc0aContract(ctx) {
|
|
8
|
+
const { buildDecision, PLATFORMS } = ctx;
|
|
9
|
+
describe("buildDecision contract constructor", () => {
|
|
10
|
+
test("rejects an incomplete platform matrix", () => {
|
|
11
|
+
const matrix = {
|
|
12
|
+
"linux-x64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
|
|
13
|
+
"linux-arm64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
|
|
14
|
+
"darwin-x64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "wasm" },
|
|
15
|
+
"darwin-arm64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
|
|
16
|
+
// win32-x64 omitted
|
|
17
|
+
};
|
|
18
|
+
assert.throws(() => buildDecision({
|
|
19
|
+
backend: "wasm",
|
|
20
|
+
budgetOk: true,
|
|
21
|
+
p95Ms: 18.2,
|
|
22
|
+
platformMatrix: matrix,
|
|
23
|
+
modelPath: "model.onnx",
|
|
24
|
+
modelBytes: 1,
|
|
25
|
+
modelSha256: "a".repeat(64),
|
|
26
|
+
tokenizerPath: "tokenizer.json",
|
|
27
|
+
tokenizerBytes: 1,
|
|
28
|
+
tokenizerSha256: "b".repeat(64),
|
|
29
|
+
blockedBy: [],
|
|
30
|
+
}));
|
|
31
|
+
});
|
|
32
|
+
test("builds a valid decision with opset 21 + MIT license for a complete matrix", () => {
|
|
33
|
+
const matrix = {
|
|
34
|
+
"linux-x64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
|
|
35
|
+
"linux-arm64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
|
|
36
|
+
"darwin-x64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "wasm" },
|
|
37
|
+
"darwin-arm64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
|
|
38
|
+
"win32-x64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
|
|
39
|
+
};
|
|
40
|
+
const d = buildDecision({
|
|
41
|
+
backend: "wasm",
|
|
42
|
+
budgetOk: true,
|
|
43
|
+
p95Ms: 18.2,
|
|
44
|
+
platformMatrix: matrix,
|
|
45
|
+
modelPath: "model.onnx",
|
|
46
|
+
modelBytes: 24117248,
|
|
47
|
+
modelSha256: "a".repeat(64),
|
|
48
|
+
tokenizerPath: "tokenizer.json",
|
|
49
|
+
tokenizerBytes: 50000,
|
|
50
|
+
tokenizerSha256: "b".repeat(64),
|
|
51
|
+
blockedBy: [],
|
|
52
|
+
});
|
|
53
|
+
assert.equal(d.schema, "encoder-backend-decision-v1");
|
|
54
|
+
assert.equal(d.opset, 21);
|
|
55
|
+
assert.equal(d.backend, "wasm");
|
|
56
|
+
assert.deepEqual(d.license, { spdx: "MIT", redistribution: true });
|
|
57
|
+
assert.equal(d.platformMatrix["darwin-x64"].demotion, "wasm");
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* _acceptance-vc2a-conformance.ts — ENC-001..008 conformance rows + the named
|
|
3
|
+
* assertions (ENC-ASSET-001 / ENC-DIGEST-002 / ENC-PLATFORM-003), each driven
|
|
4
|
+
* through the REAL encoder asset/runtime (no mocks). Extracted from
|
|
5
|
+
* vc2a-acceptance.test.ts so the aggregator stays under the tests/ soft limit.
|
|
6
|
+
*
|
|
7
|
+
* The aggregator passes its shared imports/helpers as a context object, so this
|
|
8
|
+
* sibling never imports the aggregator (no import cycle at module load).
|
|
9
|
+
*/
|
|
10
|
+
import { test, describe } from "node:test";
|
|
11
|
+
import assert from "node:assert/strict";
|
|
12
|
+
export function registerVc2aConformance(ctx) {
|
|
13
|
+
const { ENC_IDS, ENC_FAIL, fixture, buildDir, rmBuilt, optionsFor, createEncoderRuntime, verifyEncoderAsset, readEncoderManifest, } = ctx;
|
|
14
|
+
// -------------------------------------------------------------------------
|
|
15
|
+
// ENC-001..008 conformance rows through the real runtime
|
|
16
|
+
// -------------------------------------------------------------------------
|
|
17
|
+
describe("ENC-001..008 conformance rows", () => {
|
|
18
|
+
for (const id of ENC_IDS) {
|
|
19
|
+
test(`${id}: resolves through the real runtime to the documented result`, () => {
|
|
20
|
+
const fx = fixture(id);
|
|
21
|
+
const built = buildDir(fx.input.scenario);
|
|
22
|
+
try {
|
|
23
|
+
const rt = createEncoderRuntime(optionsFor(fx.input.scenario));
|
|
24
|
+
const load = rt.load(built.dir);
|
|
25
|
+
assert.equal(load.ok, fx.expected.ok, `${id} ok`);
|
|
26
|
+
if (!load.ok) {
|
|
27
|
+
assert.equal(load.code, fx.expected.code, `${id} exact failure code`);
|
|
28
|
+
if (fx.expected.mode)
|
|
29
|
+
assert.equal(load.mode, fx.expected.mode, `${id} mode`);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
assert.equal(load.mode, "A", `${id} should be mode A`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
rmBuilt(built);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
// -------------------------------------------------------------------------
|
|
42
|
+
// VC2A named assertions
|
|
43
|
+
// -------------------------------------------------------------------------
|
|
44
|
+
describe("VC2A named assertions", () => {
|
|
45
|
+
test("ENC-ASSET-001: opset21 manifest + matching digests load as mode A", () => {
|
|
46
|
+
const fx = fixture("ENC-ASSET-001");
|
|
47
|
+
assert.equal(fx.expected.ok, true);
|
|
48
|
+
const built = buildDir("valid");
|
|
49
|
+
try {
|
|
50
|
+
const load = createEncoderRuntime().load(built.dir);
|
|
51
|
+
assert.equal(load.ok, true);
|
|
52
|
+
if (load.ok)
|
|
53
|
+
assert.equal(load.mode, "A");
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
rmBuilt(built);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
test("ENC-DIGEST-002: one-byte model mutation demotes before load", () => {
|
|
60
|
+
const fx = fixture("ENC-DIGEST-002");
|
|
61
|
+
assert.equal(fx.expected.code, ENC_FAIL.DIGEST_MISMATCH);
|
|
62
|
+
const built = buildDir("mutate-onnx");
|
|
63
|
+
try {
|
|
64
|
+
const res = verifyEncoderAsset(built.dir, readEncoderManifest(built.dir));
|
|
65
|
+
assert.equal(res.ok, false);
|
|
66
|
+
if (!res.ok)
|
|
67
|
+
assert.equal(res.code, ENC_FAIL.DIGEST_MISMATCH);
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
rmBuilt(built);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
test("ENC-PLATFORM-003: unsupported architecture selects trigram B", () => {
|
|
74
|
+
const fx = fixture("ENC-PLATFORM-003");
|
|
75
|
+
assert.equal(fx.expected.mode, "B");
|
|
76
|
+
const built = buildDir("valid");
|
|
77
|
+
try {
|
|
78
|
+
const load = createEncoderRuntime({ platform: () => null }).load(built.dir);
|
|
79
|
+
assert.equal(load.ok, false);
|
|
80
|
+
if (!load.ok) {
|
|
81
|
+
assert.equal(load.mode, "B", "trigram B selected");
|
|
82
|
+
assert.equal(load.code, ENC_FAIL.PLATFORM_UNSUPPORTED);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
rmBuilt(built);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/** VC2A runtime invariant + injection + triad + budget acceptance suites.
|
|
2
|
+
* Extracted from vc2a-acceptance.test.ts (soft-limit compliance). Context injected. */
|
|
3
|
+
import { test, describe } from "node:test";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { mkdirSync, writeFileSync, rmSync } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
export function registerVc2aRuntime(ctx) {
|
|
8
|
+
const { ENC_FAIL, ENCODER_RSS_BUDGET_BYTES, ENCODER_LATENCY_P95_MS, tmpAsset, baseManifest, buildDir, rmBuilt, sha256, percentile, createEncoderRuntime, verifyEncoderAsset, readEncoderManifest, } = ctx;
|
|
9
|
+
// -------------------------------------------------------------------------
|
|
10
|
+
// Invariant + unique failure injection + forced triad
|
|
11
|
+
// -------------------------------------------------------------------------
|
|
12
|
+
describe("encoder runtime invariant + injection + triad", () => {
|
|
13
|
+
test("invariant: only batch1/max512 verified assets reach inference", () => {
|
|
14
|
+
const built = buildDir("valid");
|
|
15
|
+
try {
|
|
16
|
+
const rt = createEncoderRuntime();
|
|
17
|
+
const load = rt.load(built.dir);
|
|
18
|
+
assert.equal(load.ok, true);
|
|
19
|
+
if (load.ok)
|
|
20
|
+
assert.equal(load.mode, "A");
|
|
21
|
+
// dims 1..512 infer; 0 and 513+ are shape-rejected.
|
|
22
|
+
for (const n of [1, 64, 512]) {
|
|
23
|
+
const inf = rt.infer({ tokens: Array.from({ length: n }, (_, i) => i % 500) });
|
|
24
|
+
assert.equal(inf.ok, true, `dim ${n} infers`);
|
|
25
|
+
}
|
|
26
|
+
for (const n of [0, 513, 1000]) {
|
|
27
|
+
const inf = rt.infer({ tokens: Array.from({ length: n }) });
|
|
28
|
+
assert.equal(inf.ok, false, `dim ${n} shape-rejected`);
|
|
29
|
+
if (!inf.ok)
|
|
30
|
+
assert.equal(inf.code, ENC_FAIL.SHAPE_INVALID);
|
|
31
|
+
}
|
|
32
|
+
// A batch>1 manifest never reaches inference: verification demotes to B.
|
|
33
|
+
const bad = buildDir("batch-2");
|
|
34
|
+
try {
|
|
35
|
+
const checker = createEncoderRuntime();
|
|
36
|
+
const check = checker.load(bad.dir);
|
|
37
|
+
assert.equal(check.ok, false);
|
|
38
|
+
if (!check.ok)
|
|
39
|
+
assert.equal(check.code, ENC_FAIL.BATCH_INVALID);
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
rmBuilt(bad);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
rmBuilt(built);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
test("1..513 maxTokens manifests: 1..512 verify+infer, 513 demotes TOKENS_EXCEEDED", () => {
|
|
50
|
+
for (const maxTok of [1, 64, 512]) {
|
|
51
|
+
const dir = tmpAsset("vc2a-dim");
|
|
52
|
+
mkdirSync(dir, { recursive: true });
|
|
53
|
+
const onnx = Buffer.from(`dim-${maxTok}`, "binary");
|
|
54
|
+
const tok = Buffer.from('{"vocab":[]}', "utf8");
|
|
55
|
+
writeFileSync(join(dir, "model.onnx"), onnx);
|
|
56
|
+
writeFileSync(join(dir, "tokenizer.json"), tok);
|
|
57
|
+
const m = baseManifest({
|
|
58
|
+
maxTokens: maxTok,
|
|
59
|
+
onnx: { path: "model.onnx", sha256: sha256(onnx), bytes: onnx.length },
|
|
60
|
+
tokenizer: { path: "tokenizer.json", sha256: sha256(tok), bytes: tok.length },
|
|
61
|
+
});
|
|
62
|
+
writeFileSync(join(dir, "manifest.json"), JSON.stringify(m));
|
|
63
|
+
assert.equal(verifyEncoderAsset(dir, readEncoderManifest(dir)).ok, true, `maxTokens ${maxTok} verifies`);
|
|
64
|
+
const rt = createEncoderRuntime();
|
|
65
|
+
assert.equal(rt.load(dir).ok, true, `maxTokens ${maxTok} loads`);
|
|
66
|
+
const inf = rt.infer({ tokens: Array.from({ length: maxTok }) });
|
|
67
|
+
assert.equal(inf.ok, true, `cap ${maxTok} infers`);
|
|
68
|
+
rmSync(dir, { recursive: true, force: true });
|
|
69
|
+
}
|
|
70
|
+
// 513 demotes.
|
|
71
|
+
const dir513 = tmpAsset("vc2a-dim-513");
|
|
72
|
+
mkdirSync(dir513, { recursive: true });
|
|
73
|
+
const onnx513 = Buffer.from("dim-513", "binary");
|
|
74
|
+
const tok513 = Buffer.from('{"vocab":[]}', "utf8");
|
|
75
|
+
writeFileSync(join(dir513, "model.onnx"), onnx513);
|
|
76
|
+
writeFileSync(join(dir513, "tokenizer.json"), tok513);
|
|
77
|
+
const m513 = baseManifest({
|
|
78
|
+
maxTokens: 513,
|
|
79
|
+
onnx: { path: "model.onnx", sha256: sha256(onnx513), bytes: onnx513.length },
|
|
80
|
+
tokenizer: { path: "tokenizer.json", sha256: sha256(tok513), bytes: tok513.length },
|
|
81
|
+
});
|
|
82
|
+
writeFileSync(join(dir513, "manifest.json"), JSON.stringify(m513));
|
|
83
|
+
const res = verifyEncoderAsset(dir513, readEncoderManifest(dir513));
|
|
84
|
+
assert.equal(res.ok, false);
|
|
85
|
+
if (!res.ok)
|
|
86
|
+
assert.equal(res.code, ENC_FAIL.TOKENS_EXCEEDED);
|
|
87
|
+
rmSync(dir513, { recursive: true, force: true });
|
|
88
|
+
});
|
|
89
|
+
test("truncated ONNX during digest read demotes ENC_ASSET_UNREADABLE", () => {
|
|
90
|
+
// LIVE-platform manifest with absent model.onnx -> unreadable -> ASSET_UNREADABLE.
|
|
91
|
+
const built = buildDir("missing-onnx");
|
|
92
|
+
try {
|
|
93
|
+
const load = createEncoderRuntime().load(built.dir);
|
|
94
|
+
assert.equal(load.ok, false);
|
|
95
|
+
if (!load.ok) {
|
|
96
|
+
assert.equal(load.code, ENC_FAIL.ASSET_UNREADABLE);
|
|
97
|
+
assert.equal(load.mode, "B");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
rmBuilt(built);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
test("allocator failure after verification demotes ENC_ASSET_UNREADABLE", () => {
|
|
105
|
+
const built = buildDir("valid");
|
|
106
|
+
try {
|
|
107
|
+
const load = createEncoderRuntime({ host: { allocatorFails: () => true } }).load(built.dir);
|
|
108
|
+
assert.equal(load.ok, false);
|
|
109
|
+
if (!load.ok)
|
|
110
|
+
assert.equal(load.code, ENC_FAIL.ASSET_UNREADABLE);
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
rmBuilt(built);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
test("forced triad A / B / C", () => {
|
|
117
|
+
const dirA = buildDir("valid");
|
|
118
|
+
try {
|
|
119
|
+
assert.equal(createEncoderRuntime().load(dirA.dir).ok, true);
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
rmBuilt(dirA);
|
|
123
|
+
}
|
|
124
|
+
// B: missing asset => asset-free trigram.
|
|
125
|
+
const dirB = buildDir("missing-onnx");
|
|
126
|
+
try {
|
|
127
|
+
const load = createEncoderRuntime().load(dirB.dir);
|
|
128
|
+
assert.equal(load.ok, false);
|
|
129
|
+
if (!load.ok)
|
|
130
|
+
assert.equal(load.mode, "B");
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
rmBuilt(dirB);
|
|
134
|
+
}
|
|
135
|
+
// C: lexical forced by mode C (rollback path).
|
|
136
|
+
const dirC = tmpAsset("vc2a-C");
|
|
137
|
+
mkdirSync(dirC, { recursive: true });
|
|
138
|
+
try {
|
|
139
|
+
const load = createEncoderRuntime({ forcedMode: "C" }).load(dirC);
|
|
140
|
+
assert.equal(load.ok, false);
|
|
141
|
+
if (!load.ok)
|
|
142
|
+
assert.equal(load.mode, "C");
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
rmSync(dirC, { recursive: true, force: true });
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
test("acceptance budgets: infer p95 <=40ms and encoder marginal footprint <=150MiB", () => {
|
|
149
|
+
// Q02: rssBytes = encoder MARGINAL footprint, never whole-process RSS.
|
|
150
|
+
// p95 via linear interpolation — not max sample.
|
|
151
|
+
const built = buildDir("valid");
|
|
152
|
+
try {
|
|
153
|
+
const rt = createEncoderRuntime();
|
|
154
|
+
assert.equal(rt.load(built.dir).ok, true);
|
|
155
|
+
const latencies = [];
|
|
156
|
+
for (let i = 0; i < 200; i++) {
|
|
157
|
+
const inf = rt.infer({ tokens: Array.from({ length: 128 }, (_, k) => k) });
|
|
158
|
+
assert.equal(inf.ok, true);
|
|
159
|
+
if (inf.ok) {
|
|
160
|
+
latencies.push(inf.latencyMs);
|
|
161
|
+
assert.ok(inf.rssBytes <= ENCODER_RSS_BUDGET_BYTES, "encoder marginal footprint <=150MiB");
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const p95 = percentile(latencies, 0.95);
|
|
165
|
+
assert.ok(p95 <= ENCODER_LATENCY_P95_MS, `p95 ${p95} <= 40ms`);
|
|
166
|
+
}
|
|
167
|
+
finally {
|
|
168
|
+
rmBuilt(built);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
test("Q01: a long-lived runtime cannot drift over the 150MiB marginal budget", () => {
|
|
172
|
+
// selfAllocated models a REUSABLE projection buffer — must not accumulate.
|
|
173
|
+
// 100k inferences prove no irreversible budget demotion.
|
|
174
|
+
const built = buildDir("valid");
|
|
175
|
+
try {
|
|
176
|
+
const rt = createEncoderRuntime();
|
|
177
|
+
assert.equal(rt.load(built.dir).ok, true);
|
|
178
|
+
let firstRss = 0;
|
|
179
|
+
for (let i = 0; i < 100_000; i++) {
|
|
180
|
+
const inf = rt.infer({ tokens: Array.from({ length: 4 }, () => i % 500) });
|
|
181
|
+
assert.equal(inf.ok, true, `infer #${i} still ok`);
|
|
182
|
+
if (inf.ok) {
|
|
183
|
+
if (i === 0)
|
|
184
|
+
firstRss = inf.rssBytes;
|
|
185
|
+
assert.equal(inf.rssBytes, firstRss, `marginal footprint flat at infer #${i}`);
|
|
186
|
+
assert.ok(inf.rssBytes <= ENCODER_RSS_BUDGET_BYTES, `still within budget at infer #${i}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
assert.equal(rt.mode, "A", "mode A survives 100k inferences (no irreversible budget demotion)");
|
|
190
|
+
}
|
|
191
|
+
finally {
|
|
192
|
+
rmBuilt(built);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
test("Q03: per-manifest maxTokens is enforced at inference (over-cap rejected)", () => {
|
|
196
|
+
// maxTokens=64 manifest: 65..512 tokens must be SHAPE_INVALID.
|
|
197
|
+
const dir = tmpAsset("vc2a-q03");
|
|
198
|
+
mkdirSync(dir, { recursive: true });
|
|
199
|
+
const onnx = Buffer.from("q03-lowcap", "binary");
|
|
200
|
+
const tok = Buffer.from('{"vocab":[]}', "utf8");
|
|
201
|
+
writeFileSync(join(dir, "model.onnx"), onnx);
|
|
202
|
+
writeFileSync(join(dir, "tokenizer.json"), tok);
|
|
203
|
+
const m = baseManifest({
|
|
204
|
+
maxTokens: 64,
|
|
205
|
+
onnx: { path: "model.onnx", sha256: sha256(onnx), bytes: onnx.length },
|
|
206
|
+
tokenizer: { path: "tokenizer.json", sha256: sha256(tok), bytes: tok.length },
|
|
207
|
+
});
|
|
208
|
+
writeFileSync(join(dir, "manifest.json"), JSON.stringify(m));
|
|
209
|
+
try {
|
|
210
|
+
const rt = createEncoderRuntime();
|
|
211
|
+
assert.equal(rt.load(dir).ok, true, "maxTokens=64 manifest loads (mode A)");
|
|
212
|
+
assert.equal(rt.infer({ tokens: Array.from({ length: 64 }, (_, k) => k) }).ok, true, "cap 64 infers");
|
|
213
|
+
for (const over of [65, 128, 512]) {
|
|
214
|
+
const inf = rt.infer({ tokens: Array.from({ length: over }) });
|
|
215
|
+
assert.equal(inf.ok, false, `${over} tokens rejected against a 64-cap manifest`);
|
|
216
|
+
if (!inf.ok)
|
|
217
|
+
assert.equal(inf.code, ENC_FAIL.SHAPE_INVALID);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
finally {
|
|
221
|
+
rmSync(dir, { recursive: true, force: true });
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
test("Q04: MEGACOMPACT_VC2A=0 makes the default factory select mode C (rollback)", () => {
|
|
225
|
+
// Flag OFF => default factory is fixed at mode C (byte-identical predecessor).
|
|
226
|
+
const saved = process.env.MEGACOMPACT_VC2A;
|
|
227
|
+
process.env.MEGACOMPACT_VC2A = "0";
|
|
228
|
+
try {
|
|
229
|
+
// An explicitly forced "C" also reports ROLLBACK (existing contract).
|
|
230
|
+
const forced = createEncoderRuntime({ forcedMode: "C" });
|
|
231
|
+
// The default factory under flag-off must match that exactly.
|
|
232
|
+
const byFlag = createEncoderRuntime();
|
|
233
|
+
for (const rt of [forced, byFlag]) {
|
|
234
|
+
assert.equal(rt.mode, "C", "flag-off / forced runtime starts in mode C");
|
|
235
|
+
const built = buildDir("valid");
|
|
236
|
+
try {
|
|
237
|
+
const load = rt.load(built.dir);
|
|
238
|
+
assert.equal(load.ok, false);
|
|
239
|
+
if (!load.ok) {
|
|
240
|
+
assert.equal(load.mode, "C", "flag-off default factory reports mode C");
|
|
241
|
+
assert.equal(load.code, ENC_FAIL.ROLLBACK, "ROLLBACK, not MANIFEST_INVALID");
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
finally {
|
|
245
|
+
rmBuilt(built);
|
|
246
|
+
}
|
|
247
|
+
const inf = rt.infer({ tokens: [1, 2, 3] });
|
|
248
|
+
assert.equal(inf.ok, false, "no learned infer on the flag-off path");
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
finally {
|
|
252
|
+
if (saved === undefined)
|
|
253
|
+
delete process.env.MEGACOMPACT_VC2A;
|
|
254
|
+
else
|
|
255
|
+
process.env.MEGACOMPACT_VC2A = saved;
|
|
256
|
+
}
|
|
257
|
+
// Restore the module-scope pin (flag ON) for subsequent scenarios.
|
|
258
|
+
process.env.MEGACOMPACT_VC2A = "1";
|
|
259
|
+
});
|
|
260
|
+
test("all digest corruptions demote before load", () => {
|
|
261
|
+
for (const which of ["onnx", "tokenizer", "both"]) {
|
|
262
|
+
const dir = tmpAsset("vc2a-corr");
|
|
263
|
+
mkdirSync(dir, { recursive: true });
|
|
264
|
+
const onnx = Buffer.from("corrupt-me-onnx", "binary");
|
|
265
|
+
const tok = Buffer.from('{"vocab":[]}', "utf8");
|
|
266
|
+
writeFileSync(join(dir, "model.onnx"), onnx);
|
|
267
|
+
writeFileSync(join(dir, "tokenizer.json"), tok);
|
|
268
|
+
const m = baseManifest({
|
|
269
|
+
onnx: { path: "model.onnx", sha256: sha256(onnx), bytes: onnx.length },
|
|
270
|
+
tokenizer: { path: "tokenizer.json", sha256: sha256(tok), bytes: tok.length },
|
|
271
|
+
});
|
|
272
|
+
if (which === "onnx" || which === "both")
|
|
273
|
+
writeFileSync(join(dir, "model.onnx"), Buffer.concat([onnx, Buffer.from("X")]));
|
|
274
|
+
if (which === "tokenizer" || which === "both")
|
|
275
|
+
writeFileSync(join(dir, "tokenizer.json"), Buffer.concat([tok, Buffer.from("X")]));
|
|
276
|
+
writeFileSync(join(dir, "manifest.json"), JSON.stringify(m));
|
|
277
|
+
const res = verifyEncoderAsset(dir, readEncoderManifest(dir));
|
|
278
|
+
assert.equal(res.ok, false, `corrupt ${which} demotes`);
|
|
279
|
+
if (!res.ok)
|
|
280
|
+
assert.equal(res.code, ENC_FAIL.DIGEST_MISMATCH, `corrupt ${which} code`);
|
|
281
|
+
rmSync(dir, { recursive: true, force: true });
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
}
|