Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

test(fact-checker): cover the partial stance verdicts and the custody and motion gates

nirholasc553ccc5aefb
diff --git a/scripts/migrate-plaintext-secrets.mjs b/scripts/migrate-plaintext-secrets.mjs
index 887b0bd0b..450ff5c13 100755
--- a/scripts/migrate-plaintext-secrets.mjs
+++ b/scripts/migrate-plaintext-secrets.mjs
@@ -48,6 +48,8 @@
// --include A,B also migrate these, overriding the "public config" call
// --exclude A,B never migrate these
// --map ENV=secret-name pin a var to a specific Secret Manager secret
+// --no-reuse always mint a fresh secret per var, even when an
+// existing secret already holds that exact value
// --force-new-version add a version to an existing secret whose value differs
// --service/--region/--project target something other than three-ws-api
//
@@ -68,6 +70,7 @@ const argv = process.argv.slice(2);
const APPLY = argv.includes('--apply');
const VERIFY_ONLY = argv.includes('--verify');
const FORCE_NEW_VERSION = argv.includes('--force-new-version');
+const REUSE = !argv.includes('--no-reuse');
function optValue(flag, fallback) {
const i = argv.indexOf(flag);
@@ -254,11 +257,51 @@ function partition(env) {
config.push({ name, reason: 'credential-bearing name but the value is empty' });
continue;
}
- credentials.push({ name, value, reason: verdict.reason, secretName: NAME_MAP.get(name) || defaultSecretName(name) });
+ credentials.push({ name, value, reason: verdict.reason, defaultName: defaultSecretName(name) });
}
return { alreadySecret, credentials, config, review };
}
+// Several env vars legitimately hold the SAME value: one wallet key is read as
+// base58 by one consumer and base64 by another, and the platform treasury key
+// backs more than one signer slot. Minting a fresh secret per var would fan a
+// single credential across several secrets, and a later rotation would update
+// one and silently leave the others live. So the live value is matched against
+// what Secret Manager already holds and an exact match is reused.
+async function buildValueIndex() {
+ const index = new Map();
+ if (!REUSE) return index;
+ let names = [];
+ try {
+ const { stdout } = await gcloud(['secrets', 'list', '--format=value(name)']);
+ names = stdout.split('\n').map((n) => n.trim()).filter(Boolean);
+ } catch {
+ return index;
+ }
+ const digests = await Promise.all(names.map((n) => latestVersionDigest(n)));
+ names.forEach((name, i) => {
+ const d = digests[i];
+ if (!d) return;
+ if (!index.has(d)) index.set(d, []);
+ index.get(d).push(name);
+ });
+ return index;
+}
+
+function resolveSecretName(item, index) {
+ if (NAME_MAP.has(item.name)) return { secretName: NAME_MAP.get(item.name), note: 'pinned by --map' };
+ const matches = index.get(digest(item.value));
+ if (matches?.length) {
+ const preferred = matches.includes(item.defaultName) ? item.defaultName : [...matches].sort()[0];
+ const others = matches.filter((m) => m !== preferred);
+ return {
+ secretName: preferred,
+ note: `already in Secret Manager${others.length ? ` (also held by ${others.join(', ')})` : ''}`,
+ };
+ }
+ return { secretName: item.defaultName, note: 'new secret' };
+}
+
async function secretExists(name) {
try {
await gcloud(['secrets', 'describe', name, '--format=value(name)']);
@@ -388,8 +431,15 @@ async function main() {
for (const e of review) console.log(` ${e.name} (${e.reason}; --include ${e.name} to migrate it)`);
}
+ const valueIndex = credentials.length ? await buildValueIndex() : new Map();
+ for (const item of credentials) {
+ const resolved = resolveSecretName(item, valueIndex);
+ item.secretName = resolved.secretName;
+ item.nameNote = resolved.note;
+ }
+
console.log(`\nPlaintext credentials to migrate (${credentials.length}):`);
- for (const e of credentials) console.log(` ${e.name} -> ${e.secretName} (${e.reason})`);
+ for (const e of credentials) console.log(` ${e.name} -> ${e.secretName} (${e.reason}; ${e.nameNote})`);
if (VERIFY_ONLY) {
const migrated = alreadySecret.map((e) => e.name);
diff --git a/tests/api/fact-check-verdict.test.js b/tests/api/fact-check-verdict.test.js
index 548dbe4b6..c8f890caf 100644
--- a/tests/api/fact-check-verdict.test.js
+++ b/tests/api/fact-check-verdict.test.js
@@ -172,3 +172,75 @@ describe('computeVerdict: confidence semantics', () => {
}
});
});
+
+describe('computeVerdict: the partial stance cannot regress the other classes', () => {
+ // The pre-2026-09-02 rule, transcribed. Its only inputs are `supports`,
+ // `contradicts` and `neutral`, because those were the only stances the
+ // extractor could emit.
+ function legacyComputeVerdict(sources) {
+ if (sources.length < 2) return 'insufficient';
+ let weightedSupport = 0;
+ let weightedContra = 0;
+ let totalWeight = 0;
+ let stanceBearing = 0;
+ for (const s of sources) {
+ totalWeight += s.weight;
+ if (s.stance === 'supports') {
+ weightedSupport += s.weight;
+ stanceBearing++;
+ } else if (s.stance === 'contradicts') {
+ weightedContra += s.weight;
+ stanceBearing++;
+ }
+ }
+ const stanceWeight = weightedSupport + weightedContra;
+ if (totalWeight === 0 || stanceWeight === 0) return 'insufficient';
+ const coverage = stanceWeight / totalWeight;
+ if (stanceBearing === 1 && coverage < 0.3) return 'insufficient';
+ if (weightedSupport / stanceWeight >= 0.7) return 'supported';
+ if (weightedContra / stanceWeight >= 0.7) return 'contradicted';
+ return 'mixed';
+ }
+
+ // A deterministic pseudo-random generator, so a failure is reproducible.
+ function rng(seed) {
+ let state = seed >>> 0;
+ return () => {
+ state = (state * 1664525 + 1013904223) >>> 0;
+ return state / 0x100000000;
+ };
+ }
+
+ it('agrees with the legacy rule on every distribution the legacy rule could see', () => {
+ // This is the no-regression proof for `supported`, `contradicted` and
+ // `insufficient`: on any evidence set with no `partial` in it, the new
+ // calculus returns exactly the old verdict. So the only claims whose
+ // verdict can move are the ones a source actually reports as half-true,
+ // and no clear-cut claim can be pulled into the mixed band by the change.
+ const next = rng(20260902);
+ const legacyStances = ['supports', 'contradicts', 'neutral'];
+ for (let trial = 0; trial < 5000; trial++) {
+ const n = Math.floor(next() * 7);
+ const sources = Array.from({ length: n }, (_v, i) => ({
+ url: `https://example.com/${i}`,
+ stance: legacyStances[Math.floor(next() * legacyStances.length)],
+ // Real weights are authority scores in [0, 1]; 0 is reachable via
+ // the `high` strictness penalty on a low-authority source.
+ weight: Math.round(next() * 100) / 100,
+ }));
+ expect(computeVerdict(sources).verdict, JSON.stringify(sources)).toBe(
+ legacyComputeVerdict(sources),
+ );
+ }
+ });
+
+ it('replacing a partial stance with a directional one restores the legacy verdict', () => {
+ // The change is confined to what `partial` means: it is not a global
+ // re-tuning of the thresholds.
+ const base = [...of('supports', 3), ...of('contradicts', 1)];
+ const withPartial = [...base, ...of('partial', 2)];
+ expect(computeVerdict(base).verdict).toBe('supported');
+ expect(computeVerdict(withPartial).verdict).toBe('mixed');
+ expect(computeVerdict([...base, ...of('supports', 2)]).verdict).toBe('supported');
+ });
+});