Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2012,7 +2012,7 @@ jobs:
# of this feature set.
- name: Base Registry Engine schema-gated tests
if: matrix.lane == 'contracts'
run: cargo test --locked -p registry-breg --features runtime,tooling,schema --lib --test action_evidence_compiler --test proposal_hooks --test value_type_consistency
run: cargo test --locked -p registry-breg --features runtime,tooling,schema --lib --test action_evidence_compiler --test proposal_additional_forms --test proposal_hooks --test value_type_consistency

- name: BReg client contract consistency
if: matrix.lane == 'contracts'
Expand Down
42 changes: 42 additions & 0 deletions clients/typescript/tests/casework.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,45 @@ test('Casework returns an empty pending answer and rejects an undeclared bare st
assert.equal(data, undefined)
await assert.rejects(client(410).call('getReviewAsk', { path: ask }), { kind: 'unexpected', status: 410 })
})

test('Casework accepts source threads with absent optional fields and still requires message identity', async () => {
const digest = 'sha256:' + '0'.repeat(64)
const policy = { id: 'address-review', version: '1', digest }
const taskContext = {
taskId: id, requestId: id, requesterReference: 'case-1', policy,
subject: { id, source: 'registry', type: 'proposal', version: '1', digest },
context: { mode: 'current-source', reference: 'proposal-ref', bindingStatus: 'current' },
policyClosure: {
identity: policy, purpose: 'approval', stages: [], displaySchema: { type: 'object' },
context: { mode: 'current-source', provider: 'registry', contract: { id: 'context', revision: digest, schemaDigest: digest } },
retention: { terminalRetentionDays: 30, accountabilityRetentionDays: 30 },
dependencies: {
accessProfiles: [], queues: [], teams: [], clocks: [], calendars: [],
contextProvider: null, taskTemplates: [], trustedProducers: [],
inbox: { defaultPageSize: 25, maximumCandidateScan: 100, maximumSourceReads: 25,
maximumConcurrentSourceReads: 4, pageDeadlineMilliseconds: 2000 },
},
},
}
const sentAt = '2026-12-01T10:00:00.000000Z'
const official = { id, from: 'official', mine: true, sentAt, text: 'Received' }
const erased = { id: '00000000-0000-4000-8000-000000000002', from: 'party', partyRole: 'owner', mine: false, sentAt }
const link = { path: '/v1/proposals/' + id + '/messages', accessProfile: 'reviewer', operation: 'message' }
const availability = { available: true, observedRevision: 2 }
const links = {
message: { ...link, method: 'POST', ifMatch: '"proposal-2"', availability },
markRead: { ...link, method: 'POST', path: link.path + '/read', availability },
list: { ...link, method: 'GET', availability },
}
const readContext = (messages: unknown) => client(200, JSON.stringify({ ...taskContext, messages }),
{ 'content-type': 'application/json', traceparent }).call('getReviewTaskContext', { path: { task_id: id } })

const thread = { count: 2, unread: 1, lastSentAt: sentAt, items: [erased, official], links }
assert.equal((await readContext(undefined)).data.messages, undefined)
for (const messages of [{ count: 0, unread: 0, items: [], links }, { count: 2, unread: 1, lastSentAt: sentAt }, thread]) {
const { data } = await readContext(messages)
assert.deepEqual(data.messages, messages)
}
const { id: _id, ...withoutIdentity } = official
await assert.rejects(readContext({ ...thread, items: [withoutIdentity] }), { kind: 'unexpected', reason: 'schema', status: 200 })
})
2 changes: 2 additions & 0 deletions clients/typescript/tests/live/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,8 @@ function stageMainPlan(root: string, dhis2Origin: string): string {
'read-updated-contact': 'editor',
'start-registration': 'editor',
'submit-registration': 'editor',
'await-registration': 'editor',
'read-registered-contact': 'editor',
},
},
journeyFile: 'dev-journeys.yaml',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,9 @@ impl Breg {
{"action": "register-household", "operations": ["start"], "targets": [{"recordType": "household", "rowBoundaries": [{"field": "owner", "claim": "sub", "operator": "equals"}]}]}
],
"proposals": [
{"action": "propose-item", "operations": ["get", "submit"], "ownership": "caller", "targets": [{"recordType": "item", "rowBoundaries": [{"field": "owner", "claim": "sub", "operator": "equals"}]}]},
{"action": "manual-item", "operations": ["get", "submit", "apply"], "ownership": "caller", "targets": [{"recordType": "item", "rowBoundaries": [{"field": "owner", "claim": "sub", "operator": "equals"}]}]},
{"action": "register-household", "operations": ["get", "submit"], "ownership": "caller", "targets": [{"recordType": "household", "rowBoundaries": [{"field": "owner", "claim": "sub", "operator": "equals"}]}]}
{"action": "propose-item", "operations": ["get", "submit"], "party": "owner", "targets": [{"recordType": "item", "rowBoundaries": [{"field": "owner", "claim": "sub", "operator": "equals"}]}]},
{"action": "manual-item", "operations": ["get", "submit", "apply"], "party": "owner", "targets": [{"recordType": "item", "rowBoundaries": [{"field": "owner", "claim": "sub", "operator": "equals"}]}]},
{"action": "register-household", "operations": ["get", "submit"], "party": "owner", "targets": [{"recordType": "household", "rowBoundaries": [{"field": "owner", "claim": "sub", "operator": "equals"}]}]}
]
}
}}
Expand Down
2 changes: 1 addition & 1 deletion crates/registry-adapter/tests/facade_refusals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ async fn every_refusal_keeps_its_answer_and_is_counted_and_logged_under_its_chec
expected.values().sum::<u64>(),
"no other check was counted: {counted:?}"
);
assert_eq!(counted.len(), 45, "every check is declared at zero");
assert_eq!(counted.len(), 46, "every check is declared at zero");

let stderr = served.wait_for_stderr("\"request refused\"", STDERR_WAIT);
std::thread::sleep(Duration::from_millis(300));
Expand Down
55 changes: 54 additions & 1 deletion crates/registry-breg-client-node/__test__/additions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ test('additions preserve the submitted version and use exact binary exchanges',
const document = {id, actionId: 'correct', actionRevision: revision, submissionVersion: 1, revision: 2, state: 'submitted', effectDigest: revision, links: {},
additions: {other: {id: 'other', maximumBytes: 64, maximumCount: 2, contentTypes: ['text/plain'], classification: 'restricted', items: [],
links: {add: {method: 'POST', path: `/v1/proposals/${id}/additions/other`, accessProfile: 'writer', operation: 'add', ifMatch: '"condition"'}}}}};
const formId = 'details';
const formEntryId = '00000000-0000-4000-8000-000000000004';
const formPath = `/v1/proposals/${id}/additional-forms/${formId}`;
const messageId = '00000000-0000-4000-8000-000000000005';
const threadPath = `/v1/proposals/${id}/messages`;
const requests = [];
const server = http.createServer(async (request, response) => {
const chunks = []; for await (const chunk of request) chunks.push(chunk);
Expand All @@ -27,7 +32,30 @@ test('additions preserve the submitted version and use exact binary exchanges',
response.setHeader('x-content-type-options', 'nosniff'); response.setHeader('vary', 'authorization');
return response.end(bytes);
}
if (request.method === 'POST') {
if (request.url.includes(threadPath)) {
response.setHeader('content-type', 'application/json'); response.setHeader('vary', 'authorization, accept');
if (request.method === 'GET') return response.end(JSON.stringify({items: document.messages.items}));
if (!request.url.includes(threadPath + '/read')) {
const {text} = JSON.parse(requests.at(-1).body.toString());
document.revision++;
for (const link of Object.values(document.messages.links)) link.availability.observedRevision = document.revision;
document.additions.other.links.add.availability.observedRevision = document.revision;
document.additionalForms[formId].links.add.availability.observedRevision = document.revision;
document.messages.count++;
document.messages.items.unshift({id: messageId, from: 'party', partyRole: 'owner',
mine: true, sentAt: '2026-11-27T00:00:00Z', text});
}
return response.end(JSON.stringify(document));
}
if (request.method === 'POST' && request.url.includes(formPath)) {
document.revision++;
document.formEntryId = formEntryId;
document.additions.other.links.add.availability.observedRevision = document.revision;
const slot = document.additionalForms[formId];
slot.items.push({id: formEntryId, submissionVersion: 1, addedAt: '2026-11-27T00:00:00Z',
input: JSON.parse(requests.at(-1).body.toString()).input});
slot.links.add.availability.observedRevision = document.revision;
} else if (request.method === 'POST') {
document.revision++;
document.additions.other.items.push({id: file, submissionVersion: 1, sha256: createHash('sha256').update(bytes).digest('hex'),
byteSize: bytes.length, contentType: 'text/plain', addedAt: '2026-11-27T00:00:00Z', verificationStatus: 'notRequired',
Expand Down Expand Up @@ -60,5 +88,30 @@ test('additions preserve the submitted version and use exact binary exchanges',
const retained = await client.getProposal(contract.selectProposalGet('writer'), id);
assert.equal(JSON.parse(retained.documentJson).additions.other.items.length, 2);
assert.deepEqual((await client.downloadProposalAddition(retained, file)).body, bytes);
document.additionalForms = {[formId]: {id: formId, maximumCount: 2, items: [],
links: {add: {method: 'POST', path: formPath, accessProfile: 'writer', operation: 'add',
ifMatch: '"form-condition"', availability: {available: true, observedRevision: document.revision}}}}};
const withForm = await client.getProposal(contract.selectProposalGet('writer'), id);
const sent = await client.addProposalFormEntry(withForm, formId, {confirmed: true}, 'form-one');
assert.equal(JSON.parse(sent.documentJson).formEntryId, formEntryId);
assert.deepEqual(JSON.parse(requests.at(-1).body.toString()), {input: {confirmed: true}});
assert.equal(requests.at(-1).headers['idempotency-key'], 'form-one');
assert.equal(requests.at(-1).headers['if-match'], '"form-condition"');
const threadLink = (method, tail = '') => ({method, path: threadPath + tail, accessProfile: 'writer',
operation: 'message', availability: {available: true, observedRevision: document.revision}});
document.messages = {count: 0, unread: 0, items: [], links: {
message: {...threadLink('POST'), ifMatch: '"message-condition"'},
markRead: threadLink('POST', '/read'), list: threadLink('GET'),
}};
const current = await client.getProposal(contract.selectProposalGet('writer'), id);
const delivered = await client.sendProposalMessage(current, '<b>literal</b>', 'send-one');
assert.equal(JSON.parse(delivered.documentJson).messages.items[0].text, '<b>literal</b>');
assert.equal(requests.at(-1).headers['idempotency-key'], 'send-one');
const page = await client.listProposalMessages(delivered, null, 2);
assert.equal(page.value.items[0].id, messageId);
await client.markProposalMessagesRead(delivered, messageId);
assert.deepEqual(JSON.parse(requests.at(-1).body.toString()), {through: messageId});
assert.equal(requests.at(-1).headers['if-match'], undefined);
assert.equal(requests.at(-1).headers['idempotency-key'], undefined);
} finally { await new Promise(resolve => server.close(resolve)); }
});
9 changes: 6 additions & 3 deletions crates/registry-breg-client-node/__test__/proposals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ const id = '00000000-0000-4000-8000-000000000001';
const metadata = {
id: 'proposal-client', version: '1', revision, metadataVersion: '2', recordTypes: [], operations: [],
proposals: {method: 'GET', path: '/v1/proposals', accessProfiles: ['author'],
actions: [{actionId: 'correct', accessProfile: 'author', operations: ['get', 'list', 'submit'], readableInputs: [], readableContextFields: []}],
actions: [{actionId: 'correct', accessProfile: 'author', party: 'owner', operations: ['get', 'list', 'submit'], readableInputs: [], writableInputs: ['address'], readableContextFields: []}],
get: {method: 'GET', path: '/v1/proposals/{proposal_id}', accessProfiles: ['author']}},
actions: [{id: 'correct', apiName: 'correct', revision, display: {}, execution: {mode: 'proposal'},
attachments: [{id: 'supporting-file', required: true, contentTypes: ['application/pdf'], maximumBytes: 1024}],
route: '/v1/actions/correct/proposals', inputMode: 'fixed', inputs: [
{id: 'address', apiName: 'address', required: true, nullable: false, classification: 'internal',
schema: {type: 'string', minLength: 1, maxLength: 100},
fieldType: {type: 'string', minimumLength: 1, maximumLength: 100}},
], referenceInputs: [], requiredConditionKeys: [], resultEffects: [],
], referenceInputs: [], requiredConditionKeys: [], resultEffects: [], subject: {input: 'address'}, writableInputs: ['address'],
access: {selectedProfile: 'author'}, routes: {start: {method: 'POST', path: '/v1/actions/correct/proposals', operationId: 'actions.correct.start',
requiresIdempotencyKey: true, inputSchema: 'action-correct-invoke-input', responseSchema: 'action-correct-invoke-response'}},
bounds: {maximumTargets: 16, maximumFieldMutations: 128, maximumSnapshotBytes: 2097152}}],
};
const proposal = {id, actionId: 'correct', actionRevision: revision, submissionVersion: 1, revision: 1, state: 'draft', links: {
const proposal = {id, actionId: 'correct', actionRevision: revision, submissionVersion: 1, revision: 1, state: 'draft', partyRole: 'owner', links: {
self: {method: 'GET', path: `/v1/proposals/${id}`, accessProfile: 'author', operation: 'get'},
edit: {method: 'POST', path: `/v1/proposals/${id}/edit`, accessProfile: 'author', operation: 'edit', ifMatch: '"draft-condition"'},
submit: {method: 'POST', path: `/v1/proposals/${id}/submit`, accessProfile: 'author', operation: 'submit', ifMatch: '"draft-condition"'},
Expand Down Expand Up @@ -86,10 +86,13 @@ test('proposal object methods preserve exact bodies and refuse JSON strings befo
const client = new BaseRegistryClient({baseUrl: `http://127.0.0.1:${server.address().port}/tenant/`});
const contract = await client.registryContract('author');
assert.deepEqual(contract.proposalActions, metadata.proposals.actions);
assert.equal(contract.actions[0].subjectInput, 'address');
assert.deepEqual(contract.actions[0].writableInputs, ['address']);
assert.deepEqual(contract.actions[0].attachments, metadata.actions[0].attachments);
const getBinding = contract.selectProposalGet('author');
const located = await client.getProposal(getBinding, id);
assert.equal(located.identifier, id);
assert.equal(JSON.parse(located.documentJson).partyRole, 'owner');
assert.equal(requests.at(-1).url, `/tenant/v1/proposals/${id}?accessProfile=author`);
const getCount = requests.length;
for (const invalid of ['../secret', id.toUpperCase(), '00000000-0000-0000-0000-00000000000A']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ test('review-only binding reads context and exact document without Proposal Get'
const binding = contract.selectProposalReviewContext('reviewer', 'correct');
assert.ok(binding instanceof BRegProposalReviewBinding);
const observed = (await client.readProposalReviewById(binding, id)).value;
assert.equal(new URL(requests.at(-1), 'http://local').searchParams.get('include'), 'answers');
assert.deepEqual(new URL(requests.at(-1), 'http://local').searchParams.getAll('include'), ['answers', 'messages']);
const batch = await client.readProposalReviewContextBatch(binding, [id, concealedId]);
assert.deepEqual(batch.value, [observed, null]);
const batchUrl = new URL(requests.at(-1), 'http://local');
Expand Down
Loading
Loading