agent-credentials-stress.test.mjs
68 lines 2.2 KB
Raw
sha256:700fafdd1afa490919f9515d660ca6e75456bcd5bb67513abcd8757a634c01f6 docs: record AIP-b SD-21 land (KN #308) Human 10 days ago
1 /**
2 * Phase C + Lane D — stress: concurrent verify + failure persist keeps other records.
3 */
4
5 import { describe, it } from 'node:test';
6 import assert from 'node:assert/strict';
7 import {
8 mintCredential,
9 verifyCredential,
10 } from '../hub/lib/agent-credential-core.mjs';
11
12 describe('Phase C stress — concurrent verify', () => {
13 it('100 sequential verifies leave credential valid (no consume-on-use)', () => {
14 let { records, credential } = mintCredential({}, {
15 sub: 'google:1',
16 name: 'stress',
17 vault_ids: ['default'],
18 scopes: ['propose', 'vault:read'],
19 now: Date.now(),
20 });
21 for (let i = 0; i < 100; i += 1) {
22 const v = verifyCredential(records, credential, { now: Date.now() + i });
23 assert.equal(v.ok, true, `verify ${i} failed`);
24 records = v.records;
25 }
26 const last = verifyCredential(records, credential, { now: Date.now() + 1000 });
27 assert.equal(last.ok, true);
28 });
29
30 it('parallel verify clones do not invent reuse failures', async () => {
31 const { records, credential } = mintCredential({}, {
32 sub: 'google:1',
33 name: 'stress-p',
34 vault_ids: ['default'],
35 scopes: ['propose', 'vault:read'],
36 });
37 const results = await Promise.all(
38 Array.from({ length: 40 }, () =>
39 Promise.resolve(verifyCredential(records, credential))
40 )
41 );
42 assert.ok(results.every((r) => r.ok === true));
43 });
44
45 it('concurrent failure persist on one id does not drop sibling records', async () => {
46 const a = mintCredential({}, {
47 sub: 'google:1',
48 name: 'a',
49 vault_ids: ['default'],
50 scopes: ['propose', 'vault:read'],
51 });
52 const b = mintCredential(a.records, {
53 sub: 'google:1',
54 name: 'b',
55 vault_ids: ['default'],
56 scopes: ['propose', 'vault:read'],
57 });
58 const badCred = b.credential.replace(/.$/, 'x');
59 const results = await Promise.all(
60 Array.from({ length: 20 }, () => Promise.resolve(verifyCredential(b.records, badCred, { now: Date.now() })))
61 );
62 assert.ok(results.every((r) => r.ok === false && r.records));
63 const ids = Object.keys(results[0].records);
64 assert.equal(ids.length, 2);
65 assert.ok(ids.includes(a.id));
66 assert.ok(ids.includes(b.id));
67 });
68 });
File History 1 commit
sha256:700fafdd1afa490919f9515d660ca6e75456bcd5bb67513abcd8757a634c01f6 docs: record AIP-b SD-21 land (KN #308) Human 10 days ago