hosted-write-eval-kn-b-stress.test.mjs
77 lines 2.4 KB
Raw
sha256:700fafdd1afa490919f9515d660ca6e75456bcd5bb67513abcd8757a634c01f6 docs: record AIP-b SD-21 land (KN #308) Human 9 days ago
1 /**
2 * HOSTED-WRITE-EVAL-KN-b — Tier 4 stress: N create+approve cycles; no cross-user leakage.
3 */
4 import { describe, it, beforeEach, afterEach } from 'node:test';
5 import assert from 'node:assert/strict';
6 import fs from 'node:fs';
7 import os from 'node:os';
8 import path from 'node:path';
9 import { createProposal, listProposals } from '../hub/proposals-store.mjs';
10 import { personalSelfApplyAllowsApprove, SCOOLING_REVIEW_TRAY_INTENT } from '../lib/hub-proposal-personal-self-apply.mjs';
11
12 const N = 40;
13
14 describe('HOSTED-WRITE-EVAL-KN-b stress', () => {
15 /** @type {string} */
16 let dataDir;
17
18 beforeEach(() => {
19 dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'kt-hwe-stress-'));
20 });
21
22 afterEach(() => {
23 fs.rmSync(dataDir, { recursive: true, force: true });
24 });
25
26 it(`${N} matching create cycles; partition ownership stays per-actor`, () => {
27 const users = ['user:a', 'user:b'];
28 /** @type {Map<string, string[]>} */
29 const byUser = new Map(users.map((u) => [u, []]));
30
31 for (let i = 0; i < N; i++) {
32 const actor = users[i % users.length];
33 const id = `stress-${i}`;
34 const proposal = createProposal(dataDir, {
35 path: `reviewed/${id}.md`,
36 body: `body-${i}`,
37 intent: SCOOLING_REVIEW_TRAY_INTENT,
38 external_ref: `scooling.review:${id}`,
39 evaluationRequired: true,
40 proposed_by: actor,
41 vault_id: 'default',
42 });
43 assert.equal(proposal.evaluation_status, 'passed');
44 assert.equal(
45 personalSelfApplyAllowsApprove({
46 proposal,
47 hasVaultWrite: true,
48 partitionOwned: proposal.proposed_by === actor,
49 role: 'member',
50 }),
51 true,
52 );
53 // Cross-user: other actor must not claim partition ownership for this row.
54 const other = users[(i + 1) % users.length];
55 assert.equal(
56 personalSelfApplyAllowsApprove({
57 proposal,
58 hasVaultWrite: true,
59 partitionOwned: proposal.proposed_by === other,
60 role: 'member',
61 }),
62 false,
63 );
64 byUser.get(actor).push(proposal.proposal_id);
65 }
66
67 const all = listProposals(dataDir, { limit: 500 });
68 assert.equal(all.total, N);
69 for (const [actor, ids] of byUser) {
70 for (const pid of ids) {
71 const row = all.proposals.find((p) => p.proposal_id === pid);
72 assert.ok(row);
73 assert.equal(row.proposed_by, actor);
74 }
75 }
76 });
77 });
File History 1 commit
sha256:700fafdd1afa490919f9515d660ca6e75456bcd5bb67513abcd8757a634c01f6 docs: record AIP-b SD-21 land (KN #308) Human 9 days ago