Shipment-only AND/OR questions now evaluate one eventual reserve shipment or skip as a whole. Yes to AND requires every leaf, Yes to OR requires one, and No negates the complete expression. Separate answered questions remain jointly binding. The completion search considers all destination branches and owned preparation paths. Release and fulfillment apply once to the aggregate promise, and legacy flat records retain their shape. The two-condition browser builder, grouped question/history and respondent guidance, all four AI answer policies and saved continuation are connected. Nested expressions have explicit software size limits. Existing active-unused-shipment, Basic/no-Guild Advanced and module gates remain; mixed present/future predicates and unresolved rule questions are unchanged. Independent source, privacy and persistence review found no blocker. Types, lint, 4815 offline tests, build and 43 HTTP tests pass with stable source. The first typecheck caught an omitted flat-only guidance consumer and a legacy test requiring type narrowing; grouped guidance and an actual promised-state regression fix them. SQLite Basic/Advanced tests verify private reauthentication, second-OR-branch fulfillment, zero-write rejected actions, legal No skip and duplicate CAS with one result. Two fixed genuine Basic/Advanced mixed-profile games complete in 1534 accepted actions, 41 periodic private JSON restores and 0 rejected candidates. Each uses one scenario-directed compound question from an actual held Truthtrance at a real legal opportunity; AI supplies all responses and other actions. Exact card, force, typed-elite and post-setup traitor custody are checked. Initial private harness runs needed correct immutable setup configuration and full-game auction/Fedaykin inventory accounting; original failed traces remain private, and the final same-seed runs pass. The full sample tree is reconstructed exactly by replacing only the three later UI/test edits; all 219 game source files match the samples. No game logic changed after those runs. Browser QA used genuine base initialization before conserved turn-two staging. The human asked twenty to Carthag OR four to Arrakeen; the AI answered Yes and shipped four to the second destination. Public grouped history survived refresh. All 6 accepted actions replay exactly, with one discarded Truthtrance, one fulfilled aggregate promise, private JSON views and original seat custody intact. This remains bounded prototype evidence, not complete Truthtrance or mode certification. All 1004 opening games and original seat/recovery records are preserved (1038 rooms after checks), including all 1005 rooms present immediately before checks. SQLite integrity and foreign-key checks pass. The healthy server was reused without restart, reset or recurring automation. Verified source tree: 1b24372fbe34e24db56e8f095c25744eeefb27581f2bc6cced2fb752f5bdcb94
86 lines
4.5 KiB
TypeScript
86 lines
4.5 KiB
TypeScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { createElement } from 'react';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import { registerHooks } from 'node:module';
|
|
import { ShipmentClaimFields, invalidShipmentClause } from '../components/shipment-claim-fields';
|
|
import { truthQuestionText, type TruthQuestion } from '../game/truthtrance';
|
|
import { applyAction, viewGame } from '../game/engine';
|
|
import { ShipmentPromises } from '../components/shipment-promises';
|
|
import { compoundShipmentGame, askCompoundShipment } from './fixture-compound-shipment';
|
|
|
|
const aliases = registerHooks({ resolve(specifier, context, next) {
|
|
return next(specifier === 'next/link' ? 'vinext/shims/link' : specifier, context);
|
|
} });
|
|
const { Truthtrance } = await import('../components/truthtrance');
|
|
aliases.deregister();
|
|
|
|
const clauses = [{ territory: 'carthag', minimum: 6 }, { territory: 'arrakeen', minimum: 4 }];
|
|
function markup(join: 'single' | 'and' | 'or', minimum = 4) {
|
|
return renderToStaticMarkup(createElement(ShipmentClaimFields, {
|
|
id: 'shipment-test', join, clauses: [clauses[0], { ...clauses[1], minimum }],
|
|
onJoin() {}, onClauses() {},
|
|
}));
|
|
}
|
|
void test('compound shipment fields distinguish one shipment from two and retain accessible per-clause labels', () => {
|
|
assert.equal((markup('single').match(/<fieldset/g) ?? []).length, 1);
|
|
for (const join of ['and', 'or'] as const) {
|
|
const html = markup(join);
|
|
assert.equal((html.match(/<fieldset/g) ?? []).length, 2);
|
|
assert.match(html, /All conditions describe the same shipment/);
|
|
assert.match(html, /A No answer requires the whole statement to be false/);
|
|
for (const index of [0, 1]) {
|
|
assert.match(html, new RegExp(`for="shipment-test-territory-${index}"`));
|
|
assert.match(html, new RegExp(`for="shipment-test-minimum-${index}"`));
|
|
}
|
|
const question: TruthQuestion = { kind: 'shipment', target: 'p', claim: { op: join, terms: clauses } };
|
|
const text = truthQuestionText(question, id => id);
|
|
assert.match(text, /Carthag/);
|
|
assert.match(text, /Arrakeen/);
|
|
assert.match(text, new RegExp(join.toUpperCase()));
|
|
}
|
|
});
|
|
|
|
void test('empty, fractional and out-of-range compound counts stay invalid rather than coercing to a different promise', () => {
|
|
for (const minimum of [NaN, 0, 2.5, 21]) {
|
|
assert.equal(invalidShipmentClause({ territory: 'arrakeen', minimum }), true);
|
|
assert.match(markup('or', minimum), /id="shipment-test-minimum-1"[^>]*aria-invalid="true"/);
|
|
}
|
|
for (const minimum of [1, 20]) assert.equal(invalidShipmentClause({ territory: 'arrakeen', minimum }), false);
|
|
});
|
|
|
|
void test('the real answer panel explains whole-expression No and offers answers only to the respondent', () => {
|
|
const g = askCompoundShipment(compoundShipmentGame(true), { op: 'or', terms: clauses });
|
|
const render = (me: string, busy = false) => renderToStaticMarkup(createElement(Truthtrance, {
|
|
game: viewGame(g, me), act() {}, busy,
|
|
}));
|
|
const own = render('p');
|
|
assert.match(own, /Answer Yes/);
|
|
assert.match(own, /Answer No/);
|
|
assert.match(own, /for AND, at least one condition must be false/);
|
|
assert.match(own, /every condition must be false/);
|
|
assert.match(render('p', true), /<button[^>]*disabled=""[^>]*>Answer Yes/);
|
|
for (const other of ['a', 'o']) {
|
|
assert.doesNotMatch(render(other), />Answer (Yes|No)</);
|
|
assert.match(render(other), /Waiting for Shipper to answer/);
|
|
}
|
|
});
|
|
|
|
void test('accepted compound promises render grouped private guidance and preserve the server completion', () => {
|
|
for (const op of ['and', 'or'] as const) for (const answer of ['yes', 'no'] as const) {
|
|
const terms = op === 'and' ? [clauses[0], { territory: 'carthag', minimum: 4 }] : clauses;
|
|
const asked = askCompoundShipment(compoundShipmentGame(true), { op, terms });
|
|
const promised = applyAction(asked, 'p', { type: 'truthAnswer', answer });
|
|
const view = viewGame(promised, 'p');
|
|
const html = renderToStaticMarkup(createElement(ShipmentPromises, { game: view, act() {}, busy: false }));
|
|
assert.match(html, new RegExp(`You answered ${answer === 'yes' ? 'Yes' : 'No'}`));
|
|
assert.match(html, new RegExp(op.toUpperCase()));
|
|
assert.match(html, /Carthag/);
|
|
assert.doesNotMatch(html, /undefined/);
|
|
if (answer === 'yes') assert.match(html, /Suggested next step/);
|
|
for (const rival of ['a', 'o']) assert.equal(renderToStaticMarkup(createElement(ShipmentPromises, {
|
|
game: viewGame(promised, rival), act() {}, busy: false,
|
|
})), '');
|
|
}
|
|
});
|