desk: booth portrait is a plain image; options_hash recomputed against the CultLib vectors
All checks were successful
Build pull request / Build pull request (pull_request) Successful in 4m9s
All checks were successful
Build pull request / Build pull request (pull_request) Successful in 4m9s
PoseAvatar renders a span, not a button, when it has no onClick. The desk recomputes each card's options_hash (RFC 8785 after NFC, SHA-256; 15 CultLib vectors) and withdraws a card that differs. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8dea8717ea
commit
0f82576d9f
12 changed files with 560 additions and 20 deletions
|
|
@ -12,7 +12,8 @@ type PoseAvatarProps = {
|
|||
alt?: boolean;
|
||||
/** Play the first-appearance pop. */
|
||||
enter?: boolean;
|
||||
onClick: React.MouseEventHandler<HTMLButtonElement>;
|
||||
/** Without it the portrait is a plain image: no button, no tab stop. */
|
||||
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
||||
};
|
||||
|
||||
export function PoseAvatar({ mind, pose, userId, alt, enter, onClick }: PoseAvatarProps) {
|
||||
|
|
@ -43,9 +44,10 @@ export function PoseAvatar({ mind, pose, userId, alt, enter, onClick }: PoseAvat
|
|||
};
|
||||
}, [src, alt]);
|
||||
|
||||
const Tag = onClick ? 'button' : 'span';
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
<Tag
|
||||
type={onClick ? 'button' : undefined}
|
||||
className={classNames(css.PoseButton, alt && css.PoseButtonAlt, enter && css.EnterPortrait)}
|
||||
style={{ shapeOutside: shape }}
|
||||
data-user-id={userId}
|
||||
|
|
@ -59,6 +61,6 @@ export function PoseAvatar({ mind, pose, userId, alt, enter, onClick }: PoseAvat
|
|||
alt={`${mind}, ${pose}`}
|
||||
draggable={false}
|
||||
/>
|
||||
</button>
|
||||
</Tag>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import React from 'react';
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { Box, Icon, IconButton, Icons, Scroll, Text } from 'folds';
|
||||
import { Page, PageContent, PageContentCenter, PageHeader } from '../../components/page';
|
||||
import { ScreenSize, useScreenSizeContext } from '../../hooks/useScreenSize';
|
||||
import { getHomePath } from '../../pages/pathUtils';
|
||||
import { DeskView } from './DeskView';
|
||||
import { unverifiedForks } from './optionsHash';
|
||||
import { deskFor } from './source';
|
||||
|
||||
const labelOf = (mind: string) => mind.charAt(0).toUpperCase() + mind.slice(1);
|
||||
|
|
@ -15,6 +16,16 @@ export function Desk() {
|
|||
const navigate = useNavigate();
|
||||
const phone = useScreenSizeContext() === ScreenSize.Mobile;
|
||||
const label = labelOf(mind);
|
||||
const projection = useMemo(() => deskFor(mind), [mind]);
|
||||
// Until the recompute finishes nothing is flagged; a card that fails is withdrawn when it lands.
|
||||
const [unverified, setUnverified] = useState<ReadonlySet<string>>(new Set());
|
||||
useEffect(() => {
|
||||
let live = true;
|
||||
unverifiedForks(projection?.questions ?? []).then((bad) => live && setUnverified(bad));
|
||||
return () => {
|
||||
live = false;
|
||||
};
|
||||
}, [projection]);
|
||||
|
||||
return (
|
||||
<Page>
|
||||
|
|
@ -35,7 +46,13 @@ export function Desk() {
|
|||
<Scroll hideTrack visibility="Hover">
|
||||
<PageContent>
|
||||
<PageContentCenter>
|
||||
<DeskView mind={mind} label={label} projection={deskFor(mind)} now={Date.now()} />
|
||||
<DeskView
|
||||
mind={mind}
|
||||
label={label}
|
||||
projection={projection}
|
||||
now={Date.now()}
|
||||
unverified={unverified}
|
||||
/>
|
||||
</PageContentCenter>
|
||||
</PageContent>
|
||||
</Scroll>
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ export const Booth = style({
|
|||
});
|
||||
|
||||
// PoseAvatar's button is laid out for message gutters; the booth takes it back into flow.
|
||||
globalStyle(`${Booth} > button`, {
|
||||
globalStyle(`${Booth} > [data-pose]`, {
|
||||
position: 'static',
|
||||
float: 'none',
|
||||
display: 'block',
|
||||
|
|
|
|||
|
|
@ -8,10 +8,21 @@ import { DeskView, SIGN_IN_NOTE } from './DeskView';
|
|||
import { NOW, STATES } from './fixtures';
|
||||
import { setDeskSource } from './source';
|
||||
|
||||
const view = (state: keyof typeof STATES, size: ScreenSize, mind = 'void') =>
|
||||
const view = (
|
||||
state: keyof typeof STATES,
|
||||
size: ScreenSize,
|
||||
mind = 'void',
|
||||
unverified = new Set<string>()
|
||||
) =>
|
||||
renderToStaticMarkup(
|
||||
<ScreenSizeProvider value={size}>
|
||||
<DeskView mind={mind} label="Void" projection={STATES[state]} now={NOW} />
|
||||
<DeskView
|
||||
mind={mind}
|
||||
label="Void"
|
||||
projection={STATES[state]}
|
||||
now={NOW}
|
||||
unverified={unverified}
|
||||
/>
|
||||
</ScreenSizeProvider>
|
||||
);
|
||||
|
||||
|
|
@ -77,6 +88,21 @@ describe('DeskView', () => {
|
|||
expect(html).toContain('data-pose="thinking"');
|
||||
expect(html).toContain('Just one fork on the desk.');
|
||||
});
|
||||
it('makes the booth portrait a plain image: no button, no tab stop', () => {
|
||||
const html = view('noAnswers', ScreenSize.Desktop);
|
||||
const booth = html.slice(html.indexOf('data-pose'));
|
||||
expect(booth).toContain('<img');
|
||||
expect(html).not.toMatch(/<button[^>]*data-pose/);
|
||||
expect(html).not.toMatch(/<[a-z]+[^>]*data-pose[^>]*tabindex/);
|
||||
expect(html).toMatch(/<span[^>]*data-pose/);
|
||||
});
|
||||
it('withdraws a card whose hash does not match and does not count it open', () => {
|
||||
const html = view('noAnswers', ScreenSize.Desktop, 'void', new Set(['c:question:plain']));
|
||||
expect(html).toContain('does not match the hash it was published with');
|
||||
expect(html).not.toContain('First way');
|
||||
expect(html).not.toContain('Just one fork');
|
||||
expect(html).toContain('Nothing is waiting');
|
||||
});
|
||||
it('shows no booth for a Mind without art rather than another face', () => {
|
||||
expect(view('noAnswers', ScreenSize.Desktop, 'nobody')).not.toContain('data-pose');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -38,6 +38,15 @@ function Row({ row }: { row: DeskRow }) {
|
|||
const phone = useScreenSizeContext() === ScreenSize.Mobile;
|
||||
// Phones list titles; a tap opens one. Wide screens show every row open.
|
||||
const [open, setOpen] = useState(!phone);
|
||||
if (row.kind === 'unverified') {
|
||||
return (
|
||||
<li className={css.Row}>
|
||||
<p className={css.Quiet}>
|
||||
A question here does not match the hash it was published with, so it is not shown.
|
||||
</p>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
if (row.kind === 'hidden') {
|
||||
return (
|
||||
<li className={css.Row}>
|
||||
|
|
@ -119,11 +128,13 @@ type DeskViewProps = {
|
|||
label: string;
|
||||
projection?: DeskProjection;
|
||||
now: number;
|
||||
/** Fork ids whose options_hash failed the recompute (optionsHash.ts). */
|
||||
unverified?: ReadonlySet<string>;
|
||||
};
|
||||
|
||||
/** One Mind's desk, read-only: a stream of rows, the recorded rulings, and the booth Persona. */
|
||||
export function DeskView({ mind, label, projection, now }: DeskViewProps) {
|
||||
const desk = buildDesk(projection, now);
|
||||
export function DeskView({ mind, label, projection, now, unverified }: DeskViewProps) {
|
||||
const desk = buildDesk(projection, now, undefined, unverified);
|
||||
const mood = deskMood(desk.counts.open, desk.counts.answered);
|
||||
return (
|
||||
<section aria-label={`${label}'s desk`}>
|
||||
|
|
@ -137,7 +148,7 @@ export function DeskView({ mind, label, projection, now }: DeskViewProps) {
|
|||
{/* Only Minds with art in the catalogue get a booth; none gets another Mind's face. */}
|
||||
{desk.published && MINDS.includes(mind) && (
|
||||
<div className={css.Booth}>
|
||||
<PoseAvatar mind={mind} pose={mood.pose} userId={mind} onClick={() => undefined} />
|
||||
<PoseAvatar mind={mind} pose={mood.pose} userId={mind} />
|
||||
<Text className={css.BoothLine} size="T200" aria-live="polite">
|
||||
{mood.line}
|
||||
</Text>
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ export type AnswerRow = {
|
|||
|
||||
export type DeskRow =
|
||||
| { kind: 'hidden'; forkId: string; hidden: Hidden }
|
||||
/** Its published options_hash is not the hash of what it shows: neither shown nor counted. */
|
||||
| { kind: 'unverified'; forkId: string }
|
||||
| {
|
||||
kind: 'question';
|
||||
forkId: string;
|
||||
|
|
@ -91,7 +93,12 @@ const standing = (answers: Answer[]): Answer[] => {
|
|||
export const countOpen = (p?: DeskProjection): number =>
|
||||
p?.questions.filter((q) => !isHiddenQuestion(q) && q.status.state === 'open').length ?? 0;
|
||||
|
||||
export const buildDesk = (p: DeskProjection | undefined, now: number, viewerId?: string): Desk => {
|
||||
export const buildDesk = (
|
||||
p: DeskProjection | undefined,
|
||||
now: number,
|
||||
viewerId?: string,
|
||||
unverified: ReadonlySet<string> = new Set()
|
||||
): Desk => {
|
||||
if (!p?.syncedAt) {
|
||||
return {
|
||||
published: false,
|
||||
|
|
@ -122,6 +129,10 @@ export const buildDesk = (p: DeskProjection | undefined, now: number, viewerId?:
|
|||
return;
|
||||
}
|
||||
if (q.status.state !== 'open') return;
|
||||
if (unverified.has(q.fork_id)) {
|
||||
open.push({ kind: 'unverified', forkId: q.fork_id });
|
||||
return;
|
||||
}
|
||||
const mine = standing(p.answers.filter((a) => a.fork_id === q.fork_id));
|
||||
if (viewerId && mine.some((a) => a.answerer === viewerId && !a.hidden)) answered += 1;
|
||||
const days = ageDays(q.askedAt, now);
|
||||
|
|
@ -148,6 +159,6 @@ export const buildDesk = (p: DeskProjection | undefined, now: number, viewerId?:
|
|||
stale: now - Date.parse(p.syncedAt) > STALE_MS,
|
||||
open,
|
||||
recorded,
|
||||
counts: { open: countOpen(p), answered },
|
||||
counts: { open: open.filter((r) => r.kind === 'question').length, answered },
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -21,17 +21,17 @@ export type Question = {
|
|||
body: string;
|
||||
/** `id` is the option's label. */
|
||||
options: { id: string; text: string }[];
|
||||
/** An option label. Never preselected. */
|
||||
recommendation?: string;
|
||||
/** An option label; never nil. Never preselected. */
|
||||
recommendation: string;
|
||||
/** `questionId` only where the line cites one question verbatim. */
|
||||
dependsOn: { text: string; questionId?: string }[];
|
||||
/** An ISO instant: the question's receipt `committed_at`. */
|
||||
askedAt: string;
|
||||
status: QuestionStatus;
|
||||
/**
|
||||
* Publisher's sha256 over canonical JSON of what is shown (id, title, body, options, recommendation,
|
||||
* depends). Slice 1 carries it and does not recompute it: the canonicalization has no golden vector
|
||||
* pinned across Rust and TS yet, and a recompute against an unpinned form would prove nothing.
|
||||
* Publisher's hash of what is shown. The desk recomputes it (optionsHash.ts, pinned to the CultLib vectors)
|
||||
* and refuses to show or answer a card whose hash differs. The receiver rejects an answer carrying a hash
|
||||
* it did not publish; sending is slice 2.
|
||||
*/
|
||||
options_hash: string;
|
||||
};
|
||||
|
|
|
|||
50
src/app/features/desk/optionsHash.test.ts
Normal file
50
src/app/features/desk/optionsHash.test.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import vectors from './optionsHashVectors.json';
|
||||
import { STATES } from './fixtures';
|
||||
import { Question } from './feedback';
|
||||
import { canonicalShown, optionsHash, shownOf, unverifiedForks } from './optionsHash';
|
||||
|
||||
describe('options_hash against the CultLib vectors', () => {
|
||||
it('has all fifteen vectors', () => {
|
||||
expect(vectors.optionsHash).toHaveLength(15);
|
||||
});
|
||||
vectors.optionsHash.forEach((v) => {
|
||||
it(`${v.name}: canonical bytes and sha256 match`, async () => {
|
||||
expect(canonicalShown(v)).toBe(v.canonical);
|
||||
expect(await optionsHash(v)).toBe(v.sha256);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('unverifiedForks', () => {
|
||||
const card = async (): Promise<Question> => {
|
||||
const q = structuredClone(STATES.noAnswers.questions[0]) as Question;
|
||||
return { ...q, options_hash: await optionsHash(shownOf(q)) };
|
||||
};
|
||||
it('passes a card whose hash is the hash of what it shows', async () => {
|
||||
expect(await unverifiedForks([await card()])).toEqual(new Set());
|
||||
});
|
||||
it('flags a card whose shown text, option, recommendation or depends changed after hashing', async () => {
|
||||
const q = await card();
|
||||
const edits: Partial<Question>[] = [
|
||||
{ title: 'Other' },
|
||||
{ body: 'Other context.' },
|
||||
{ options: [...q.options].reverse() },
|
||||
{ recommendation: 'A' },
|
||||
{ dependsOn: [{ text: 'new line' }] },
|
||||
];
|
||||
await Promise.all(
|
||||
edits.map(async (e) =>
|
||||
expect(await unverifiedForks([{ ...q, ...e }]), JSON.stringify(Object.keys(e))).toEqual(
|
||||
new Set([q.fork_id])
|
||||
)
|
||||
)
|
||||
);
|
||||
});
|
||||
it('does not read fork_id, status or asked time, which are not shown members', async () => {
|
||||
const q = await card();
|
||||
expect(
|
||||
await unverifiedForks([{ ...q, fork_id: 'x:question:y', askedAt: '2020-01-01T00:00:00Z' }])
|
||||
).toEqual(new Set());
|
||||
});
|
||||
});
|
||||
57
src/app/features/desk/optionsHash.ts
Normal file
57
src/app/features/desk/optionsHash.ts
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import { DeskProjection, Question, isHiddenQuestion } from './feedback';
|
||||
|
||||
// The hash and its canonical bytes are specified in CultLib contracts/cultnet/governance/fork-card.md
|
||||
// ("Options hash", rule owner: Heimdall's binding file 1.2); the vectors in optionsHashVectors.json pin this code to it.
|
||||
|
||||
const jstr = (s: string): string => {
|
||||
let out = '"';
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const ch of s.normalize('NFC')) {
|
||||
const o = ch.codePointAt(0) as number;
|
||||
const named: Record<number, string> = { 8: '\\b', 9: '\\t', 10: '\\n', 12: '\\f', 13: '\\r' };
|
||||
if (ch === '"') out += '\\"';
|
||||
else if (ch === '\\') out += '\\\\';
|
||||
else if (named[o]) out += named[o];
|
||||
else out += o < 0x20 ? `\\u${o.toString(16).padStart(4, '0')}` : ch;
|
||||
}
|
||||
return `${out}"`;
|
||||
};
|
||||
|
||||
export type Shown = Pick<Question, 'title' | 'options' | 'recommendation'> & {
|
||||
context: string;
|
||||
depends: string[];
|
||||
};
|
||||
|
||||
/** The five shown members as RFC 8785 JSON, keys already in sorted order. */
|
||||
export const canonicalShown = (c: Shown): string =>
|
||||
`{"context":${jstr(c.context)},"depends":[${c.depends.map(jstr).join(',')}],"options":[${c.options
|
||||
.map((o) => `{"id":${jstr(o.id)},"text":${jstr(o.text)}}`)
|
||||
.join(',')}],"recommendation":${jstr(c.recommendation)},"title":${jstr(c.title)}}`;
|
||||
|
||||
export const shownOf = (q: Question): Shown => ({
|
||||
title: q.title,
|
||||
context: q.body,
|
||||
options: q.options,
|
||||
recommendation: q.recommendation,
|
||||
depends: q.dependsOn.map((d) => d.text),
|
||||
});
|
||||
|
||||
export const optionsHash = async (c: Shown): Promise<string> => {
|
||||
const bytes = new TextEncoder().encode(canonicalShown(c));
|
||||
const digest = await crypto.subtle.digest('SHA-256', bytes);
|
||||
return Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, '0')).join('');
|
||||
};
|
||||
|
||||
/** Fork ids whose published `options_hash` is not the hash of what the card shows. */
|
||||
export const unverifiedForks = async (
|
||||
questions: DeskProjection['questions']
|
||||
): Promise<Set<string>> => {
|
||||
const bad = new Set<string>();
|
||||
await Promise.all(
|
||||
questions.map(async (q) => {
|
||||
if (isHiddenQuestion(q)) return;
|
||||
if ((await optionsHash(shownOf(q))) !== q.options_hash) bad.add(q.fork_id);
|
||||
})
|
||||
);
|
||||
return bad;
|
||||
};
|
||||
346
src/app/features/desk/optionsHashVectors.json
Normal file
346
src/app/features/desk/optionsHashVectors.json
Normal file
|
|
@ -0,0 +1,346 @@
|
|||
{
|
||||
"source": "GameCult/CultLib contracts/cultnet/governance/fork-card-vectors.json, `optionsHash` member only, values unchanged (re-escaped to ASCII so TypeScript parses it), from CultLib a499c581 (file last changed in 8ca1d184). Rule: contracts/cultnet/governance/fork-card.md, 'Options hash'.",
|
||||
"optionsHash": [
|
||||
{
|
||||
"name": "heimdall_A_five_members",
|
||||
"heimdall": "A",
|
||||
"title": "Slot mark consent",
|
||||
"context": "Should a slot mark be shared?",
|
||||
"options": [
|
||||
{
|
||||
"id": "yes",
|
||||
"text": "Share it."
|
||||
},
|
||||
{
|
||||
"id": "no",
|
||||
"text": "Keep it local."
|
||||
}
|
||||
],
|
||||
"recommendation": "no",
|
||||
"depends": [
|
||||
"gamecult-chat:question:file-zone-audience"
|
||||
],
|
||||
"canonical": "{\"context\":\"Should a slot mark be shared?\",\"depends\":[\"gamecult-chat:question:file-zone-audience\"],\"options\":[{\"id\":\"yes\",\"text\":\"Share it.\"},{\"id\":\"no\",\"text\":\"Keep it local.\"}],\"recommendation\":\"no\",\"title\":\"Slot mark consent\"}",
|
||||
"canonicalHex": "7B22636F6E74657874223A2253686F756C64206120736C6F74206D61726B206265207368617265643F222C22646570656E6473223A5B2267616D6563756C742D636861743A7175657374696F6E3A66696C652D7A6F6E652D61756469656E6365225D2C226F7074696F6E73223A5B7B226964223A22796573222C2274657874223A2253686172652069742E227D2C7B226964223A226E6F222C2274657874223A224B656570206974206C6F63616C2E227D5D2C227265636F6D6D656E646174696F6E223A226E6F222C227469746C65223A22536C6F74206D61726B20636F6E73656E74227D",
|
||||
"sha256": "7d95fc87d532420611fe415c1def27a3447617bb68235f46e3af130aea361c48"
|
||||
},
|
||||
{
|
||||
"name": "heimdall_B_recommendation_changed",
|
||||
"heimdall": "B",
|
||||
"title": "Slot mark consent",
|
||||
"context": "Should a slot mark be shared?",
|
||||
"options": [
|
||||
{
|
||||
"id": "yes",
|
||||
"text": "Share it."
|
||||
},
|
||||
{
|
||||
"id": "no",
|
||||
"text": "Keep it local."
|
||||
}
|
||||
],
|
||||
"recommendation": "yes",
|
||||
"depends": [
|
||||
"gamecult-chat:question:file-zone-audience"
|
||||
],
|
||||
"canonical": "{\"context\":\"Should a slot mark be shared?\",\"depends\":[\"gamecult-chat:question:file-zone-audience\"],\"options\":[{\"id\":\"yes\",\"text\":\"Share it.\"},{\"id\":\"no\",\"text\":\"Keep it local.\"}],\"recommendation\":\"yes\",\"title\":\"Slot mark consent\"}",
|
||||
"canonicalHex": "7B22636F6E74657874223A2253686F756C64206120736C6F74206D61726B206265207368617265643F222C22646570656E6473223A5B2267616D6563756C742D636861743A7175657374696F6E3A66696C652D7A6F6E652D61756469656E6365225D2C226F7074696F6E73223A5B7B226964223A22796573222C2274657874223A2253686172652069742E227D2C7B226964223A226E6F222C2274657874223A224B656570206974206C6F63616C2E227D5D2C227265636F6D6D656E646174696F6E223A22796573222C227469746C65223A22536C6F74206D61726B20636F6E73656E74227D",
|
||||
"sha256": "14b8ffbdb61106dbc06f69f3fc8e2072af7a205d766e4cc040e89733013d54dc"
|
||||
},
|
||||
{
|
||||
"name": "heimdall_C_option_order_changed",
|
||||
"heimdall": "C",
|
||||
"title": "Slot mark consent",
|
||||
"context": "Should a slot mark be shared?",
|
||||
"options": [
|
||||
{
|
||||
"id": "no",
|
||||
"text": "Keep it local."
|
||||
},
|
||||
{
|
||||
"id": "yes",
|
||||
"text": "Share it."
|
||||
}
|
||||
],
|
||||
"recommendation": "no",
|
||||
"depends": [
|
||||
"gamecult-chat:question:file-zone-audience"
|
||||
],
|
||||
"canonical": "{\"context\":\"Should a slot mark be shared?\",\"depends\":[\"gamecult-chat:question:file-zone-audience\"],\"options\":[{\"id\":\"no\",\"text\":\"Keep it local.\"},{\"id\":\"yes\",\"text\":\"Share it.\"}],\"recommendation\":\"no\",\"title\":\"Slot mark consent\"}",
|
||||
"canonicalHex": "7B22636F6E74657874223A2253686F756C64206120736C6F74206D61726B206265207368617265643F222C22646570656E6473223A5B2267616D6563756C742D636861743A7175657374696F6E3A66696C652D7A6F6E652D61756469656E6365225D2C226F7074696F6E73223A5B7B226964223A226E6F222C2274657874223A224B656570206974206C6F63616C2E227D2C7B226964223A22796573222C2274657874223A2253686172652069742E227D5D2C227265636F6D6D656E646174696F6E223A226E6F222C227469746C65223A22536C6F74206D61726B20636F6E73656E74227D",
|
||||
"sha256": "ac67b41539f869f6203ac0908819df046e4328b27795743a919bd4ab390596b5"
|
||||
},
|
||||
{
|
||||
"name": "heimdall_D_nfc_escapes_astral",
|
||||
"heimdall": "D",
|
||||
"title": "Caf\u00e9 \u201cdesk\u201d",
|
||||
"context": "Line one\nLine two \u2014 \ud83d\ude00",
|
||||
"options": [
|
||||
{
|
||||
"id": "a",
|
||||
"text": "x"
|
||||
},
|
||||
{
|
||||
"id": "b",
|
||||
"text": "y"
|
||||
}
|
||||
],
|
||||
"recommendation": "a",
|
||||
"depends": [],
|
||||
"canonical": "{\"context\":\"Line one\\nLine two \u2014 \ud83d\ude00\",\"depends\":[],\"options\":[{\"id\":\"a\",\"text\":\"x\"},{\"id\":\"b\",\"text\":\"y\"}],\"recommendation\":\"a\",\"title\":\"Caf\u00e9 \u201cdesk\u201d\"}",
|
||||
"canonicalHex": "7B22636F6E74657874223A224C696E65206F6E655C6E4C696E652074776F20E2809420F09F9880222C22646570656E6473223A5B5D2C226F7074696F6E73223A5B7B226964223A2261222C2274657874223A2278227D2C7B226964223A2262222C2274657874223A2279227D5D2C227265636F6D6D656E646174696F6E223A2261222C227469746C65223A22436166C3A920E2809C6465736BE2809D227D",
|
||||
"sha256": "71d5c413478ad06aaa1cbdd9e91c53f0cb4cef1dbd4c51bf3d473bccc6a5a272"
|
||||
},
|
||||
{
|
||||
"name": "heimdall_E_decomposed_equals_D",
|
||||
"heimdall": "E",
|
||||
"title": "Cafe\u0301 \u201cdesk\u201d",
|
||||
"context": "Line one\nLine two \u2014 \ud83d\ude00",
|
||||
"options": [
|
||||
{
|
||||
"id": "a",
|
||||
"text": "x"
|
||||
},
|
||||
{
|
||||
"id": "b",
|
||||
"text": "y"
|
||||
}
|
||||
],
|
||||
"recommendation": "a",
|
||||
"depends": [],
|
||||
"canonical": "{\"context\":\"Line one\\nLine two \u2014 \ud83d\ude00\",\"depends\":[],\"options\":[{\"id\":\"a\",\"text\":\"x\"},{\"id\":\"b\",\"text\":\"y\"}],\"recommendation\":\"a\",\"title\":\"Caf\u00e9 \u201cdesk\u201d\"}",
|
||||
"canonicalHex": "7B22636F6E74657874223A224C696E65206F6E655C6E4C696E652074776F20E2809420F09F9880222C22646570656E6473223A5B5D2C226F7074696F6E73223A5B7B226964223A2261222C2274657874223A2278227D2C7B226964223A2262222C2274657874223A2279227D5D2C227265636F6D6D656E646174696F6E223A2261222C227469746C65223A22436166C3A920E2809C6465736BE2809D227D",
|
||||
"sha256": "71d5c413478ad06aaa1cbdd9e91c53f0cb4cef1dbd4c51bf3d473bccc6a5a272"
|
||||
},
|
||||
{
|
||||
"name": "heimdall_F_option_id_changed",
|
||||
"heimdall": "F",
|
||||
"title": "Slot mark consent",
|
||||
"context": "Should a slot mark be shared?",
|
||||
"options": [
|
||||
{
|
||||
"id": "share",
|
||||
"text": "Share it."
|
||||
},
|
||||
{
|
||||
"id": "no",
|
||||
"text": "Keep it local."
|
||||
}
|
||||
],
|
||||
"recommendation": "no",
|
||||
"depends": [
|
||||
"gamecult-chat:question:file-zone-audience"
|
||||
],
|
||||
"canonical": "{\"context\":\"Should a slot mark be shared?\",\"depends\":[\"gamecult-chat:question:file-zone-audience\"],\"options\":[{\"id\":\"share\",\"text\":\"Share it.\"},{\"id\":\"no\",\"text\":\"Keep it local.\"}],\"recommendation\":\"no\",\"title\":\"Slot mark consent\"}",
|
||||
"canonicalHex": "7B22636F6E74657874223A2253686F756C64206120736C6F74206D61726B206265207368617265643F222C22646570656E6473223A5B2267616D6563756C742D636861743A7175657374696F6E3A66696C652D7A6F6E652D61756469656E6365225D2C226F7074696F6E73223A5B7B226964223A227368617265222C2274657874223A2253686172652069742E227D2C7B226964223A226E6F222C2274657874223A224B656570206974206C6F63616C2E227D5D2C227265636F6D6D656E646174696F6E223A226E6F222C227469746C65223A22536C6F74206D61726B20636F6E73656E74227D",
|
||||
"sha256": "fb53aa3a9f7e74029f755d774064eedd240ab90d8fc64723f97c31b3d2846d40"
|
||||
},
|
||||
{
|
||||
"name": "heimdall_G_depends_emptied",
|
||||
"heimdall": "G",
|
||||
"title": "Slot mark consent",
|
||||
"context": "Should a slot mark be shared?",
|
||||
"options": [
|
||||
{
|
||||
"id": "yes",
|
||||
"text": "Share it."
|
||||
},
|
||||
{
|
||||
"id": "no",
|
||||
"text": "Keep it local."
|
||||
}
|
||||
],
|
||||
"recommendation": "no",
|
||||
"depends": [],
|
||||
"canonical": "{\"context\":\"Should a slot mark be shared?\",\"depends\":[],\"options\":[{\"id\":\"yes\",\"text\":\"Share it.\"},{\"id\":\"no\",\"text\":\"Keep it local.\"}],\"recommendation\":\"no\",\"title\":\"Slot mark consent\"}",
|
||||
"canonicalHex": "7B22636F6E74657874223A2253686F756C64206120736C6F74206D61726B206265207368617265643F222C22646570656E6473223A5B5D2C226F7074696F6E73223A5B7B226964223A22796573222C2274657874223A2253686172652069742E227D2C7B226964223A226E6F222C2274657874223A224B656570206974206C6F63616C2E227D5D2C227265636F6D6D656E646174696F6E223A226E6F222C227469746C65223A22536C6F74206D61726B20636F6E73656E74227D",
|
||||
"sha256": "f856edce121db4121b5f1af400b1c471ebbfa6579a042aca9a34ae31c15f5c86"
|
||||
},
|
||||
{
|
||||
"name": "option_text_changed",
|
||||
"heimdall": null,
|
||||
"title": "Slot mark consent",
|
||||
"context": "Should a slot mark be shared?",
|
||||
"options": [
|
||||
{
|
||||
"id": "yes",
|
||||
"text": "Share it!"
|
||||
},
|
||||
{
|
||||
"id": "no",
|
||||
"text": "Keep it local."
|
||||
}
|
||||
],
|
||||
"recommendation": "no",
|
||||
"depends": [
|
||||
"gamecult-chat:question:file-zone-audience"
|
||||
],
|
||||
"canonical": "{\"context\":\"Should a slot mark be shared?\",\"depends\":[\"gamecult-chat:question:file-zone-audience\"],\"options\":[{\"id\":\"yes\",\"text\":\"Share it!\"},{\"id\":\"no\",\"text\":\"Keep it local.\"}],\"recommendation\":\"no\",\"title\":\"Slot mark consent\"}",
|
||||
"canonicalHex": "7B22636F6E74657874223A2253686F756C64206120736C6F74206D61726B206265207368617265643F222C22646570656E6473223A5B2267616D6563756C742D636861743A7175657374696F6E3A66696C652D7A6F6E652D61756469656E6365225D2C226F7074696F6E73223A5B7B226964223A22796573222C2274657874223A22536861726520697421227D2C7B226964223A226E6F222C2274657874223A224B656570206974206C6F63616C2E227D5D2C227265636F6D6D656E646174696F6E223A226E6F222C227469746C65223A22536C6F74206D61726B20636F6E73656E74227D",
|
||||
"sha256": "9ce0d2770497fdd2d5338e66f9f1ae1741d87301db4c793407c25762929392b6"
|
||||
},
|
||||
{
|
||||
"name": "title_changed",
|
||||
"heimdall": null,
|
||||
"title": "Slot mark consent?",
|
||||
"context": "Should a slot mark be shared?",
|
||||
"options": [
|
||||
{
|
||||
"id": "yes",
|
||||
"text": "Share it."
|
||||
},
|
||||
{
|
||||
"id": "no",
|
||||
"text": "Keep it local."
|
||||
}
|
||||
],
|
||||
"recommendation": "no",
|
||||
"depends": [
|
||||
"gamecult-chat:question:file-zone-audience"
|
||||
],
|
||||
"canonical": "{\"context\":\"Should a slot mark be shared?\",\"depends\":[\"gamecult-chat:question:file-zone-audience\"],\"options\":[{\"id\":\"yes\",\"text\":\"Share it.\"},{\"id\":\"no\",\"text\":\"Keep it local.\"}],\"recommendation\":\"no\",\"title\":\"Slot mark consent?\"}",
|
||||
"canonicalHex": "7B22636F6E74657874223A2253686F756C64206120736C6F74206D61726B206265207368617265643F222C22646570656E6473223A5B2267616D6563756C742D636861743A7175657374696F6E3A66696C652D7A6F6E652D61756469656E6365225D2C226F7074696F6E73223A5B7B226964223A22796573222C2274657874223A2253686172652069742E227D2C7B226964223A226E6F222C2274657874223A224B656570206974206C6F63616C2E227D5D2C227265636F6D6D656E646174696F6E223A226E6F222C227469746C65223A22536C6F74206D61726B20636F6E73656E743F227D",
|
||||
"sha256": "30fe0c5bc88bd21d64592a495316c30e80fcee6cacf5c63fd9a818ca5cf87d0f"
|
||||
},
|
||||
{
|
||||
"name": "context_changed",
|
||||
"heimdall": null,
|
||||
"title": "Slot mark consent",
|
||||
"context": "Should slot marks be shared?",
|
||||
"options": [
|
||||
{
|
||||
"id": "yes",
|
||||
"text": "Share it."
|
||||
},
|
||||
{
|
||||
"id": "no",
|
||||
"text": "Keep it local."
|
||||
}
|
||||
],
|
||||
"recommendation": "no",
|
||||
"depends": [
|
||||
"gamecult-chat:question:file-zone-audience"
|
||||
],
|
||||
"canonical": "{\"context\":\"Should slot marks be shared?\",\"depends\":[\"gamecult-chat:question:file-zone-audience\"],\"options\":[{\"id\":\"yes\",\"text\":\"Share it.\"},{\"id\":\"no\",\"text\":\"Keep it local.\"}],\"recommendation\":\"no\",\"title\":\"Slot mark consent\"}",
|
||||
"canonicalHex": "7B22636F6E74657874223A2253686F756C6420736C6F74206D61726B73206265207368617265643F222C22646570656E6473223A5B2267616D6563756C742D636861743A7175657374696F6E3A66696C652D7A6F6E652D61756469656E6365225D2C226F7074696F6E73223A5B7B226964223A22796573222C2274657874223A2253686172652069742E227D2C7B226964223A226E6F222C2274657874223A224B656570206974206C6F63616C2E227D5D2C227265636F6D6D656E646174696F6E223A226E6F222C227469746C65223A22536C6F74206D61726B20636F6E73656E74227D",
|
||||
"sha256": "716de65096e34fd89cc92848b667d90f5c27eeb66929da3d340cabb80155e173"
|
||||
},
|
||||
{
|
||||
"name": "depends_order_changed",
|
||||
"heimdall": null,
|
||||
"title": "Slot mark consent",
|
||||
"context": "Should a slot mark be shared?",
|
||||
"options": [
|
||||
{
|
||||
"id": "yes",
|
||||
"text": "Share it."
|
||||
},
|
||||
{
|
||||
"id": "no",
|
||||
"text": "Keep it local."
|
||||
}
|
||||
],
|
||||
"recommendation": "no",
|
||||
"depends": [
|
||||
"gamecult-chat:question:file-zone-audience",
|
||||
"x:question:y"
|
||||
],
|
||||
"canonical": "{\"context\":\"Should a slot mark be shared?\",\"depends\":[\"gamecult-chat:question:file-zone-audience\",\"x:question:y\"],\"options\":[{\"id\":\"yes\",\"text\":\"Share it.\"},{\"id\":\"no\",\"text\":\"Keep it local.\"}],\"recommendation\":\"no\",\"title\":\"Slot mark consent\"}",
|
||||
"canonicalHex": "7B22636F6E74657874223A2253686F756C64206120736C6F74206D61726B206265207368617265643F222C22646570656E6473223A5B2267616D6563756C742D636861743A7175657374696F6E3A66696C652D7A6F6E652D61756469656E6365222C22783A7175657374696F6E3A79225D2C226F7074696F6E73223A5B7B226964223A22796573222C2274657874223A2253686172652069742E227D2C7B226964223A226E6F222C2274657874223A224B656570206974206C6F63616C2E227D5D2C227265636F6D6D656E646174696F6E223A226E6F222C227469746C65223A22536C6F74206D61726B20636F6E73656E74227D",
|
||||
"sha256": "fc3f651c6f498385256fc1232d5db31ece9dcc542e391f97245d27bc9e385b3d"
|
||||
},
|
||||
{
|
||||
"name": "depends_order_changed_reversed",
|
||||
"heimdall": null,
|
||||
"title": "Slot mark consent",
|
||||
"context": "Should a slot mark be shared?",
|
||||
"options": [
|
||||
{
|
||||
"id": "yes",
|
||||
"text": "Share it."
|
||||
},
|
||||
{
|
||||
"id": "no",
|
||||
"text": "Keep it local."
|
||||
}
|
||||
],
|
||||
"recommendation": "no",
|
||||
"depends": [
|
||||
"x:question:y",
|
||||
"gamecult-chat:question:file-zone-audience"
|
||||
],
|
||||
"canonical": "{\"context\":\"Should a slot mark be shared?\",\"depends\":[\"x:question:y\",\"gamecult-chat:question:file-zone-audience\"],\"options\":[{\"id\":\"yes\",\"text\":\"Share it.\"},{\"id\":\"no\",\"text\":\"Keep it local.\"}],\"recommendation\":\"no\",\"title\":\"Slot mark consent\"}",
|
||||
"canonicalHex": "7B22636F6E74657874223A2253686F756C64206120736C6F74206D61726B206265207368617265643F222C22646570656E6473223A5B22783A7175657374696F6E3A79222C2267616D6563756C742D636861743A7175657374696F6E3A66696C652D7A6F6E652D61756469656E6365225D2C226F7074696F6E73223A5B7B226964223A22796573222C2274657874223A2253686172652069742E227D2C7B226964223A226E6F222C2274657874223A224B656570206974206C6F63616C2E227D5D2C227265636F6D6D656E646174696F6E223A226E6F222C227469746C65223A22536C6F74206D61726B20636F6E73656E74227D",
|
||||
"sha256": "b22642e30f8d68839e3a0df5bc23b83ff50a839fcecf0366a65fa6e3cf873796"
|
||||
},
|
||||
{
|
||||
"name": "hidden_members_do_not_move_it",
|
||||
"heimdall": null,
|
||||
"title": "Slot mark consent",
|
||||
"context": "Should a slot mark be shared?",
|
||||
"options": [
|
||||
{
|
||||
"id": "yes",
|
||||
"text": "Share it."
|
||||
},
|
||||
{
|
||||
"id": "no",
|
||||
"text": "Keep it local."
|
||||
}
|
||||
],
|
||||
"recommendation": "no",
|
||||
"depends": [
|
||||
"gamecult-chat:question:file-zone-audience"
|
||||
],
|
||||
"canonical": "{\"context\":\"Should a slot mark be shared?\",\"depends\":[\"gamecult-chat:question:file-zone-audience\"],\"options\":[{\"id\":\"yes\",\"text\":\"Share it.\"},{\"id\":\"no\",\"text\":\"Keep it local.\"}],\"recommendation\":\"no\",\"title\":\"Slot mark consent\"}",
|
||||
"canonicalHex": "7B22636F6E74657874223A2253686F756C64206120736C6F74206D61726B206265207368617265643F222C22646570656E6473223A5B2267616D6563756C742D636861743A7175657374696F6E3A66696C652D7A6F6E652D61756469656E6365225D2C226F7074696F6E73223A5B7B226964223A22796573222C2274657874223A2253686172652069742E227D2C7B226964223A226E6F222C2274657874223A224B656570206974206C6F63616C2E227D5D2C227265636F6D6D656E646174696F6E223A226E6F222C227469746C65223A22536C6F74206D61726B20636F6E73656E74227D",
|
||||
"sha256": "7d95fc87d532420611fe415c1def27a3447617bb68235f46e3af130aea361c48"
|
||||
},
|
||||
{
|
||||
"name": "control_characters_and_markup_are_escaped_minimally",
|
||||
"heimdall": null,
|
||||
"title": "q \" b \\ t \t n \n bell \u0007 del \u007f",
|
||||
"context": "</script> \u2028 &",
|
||||
"options": [
|
||||
{
|
||||
"id": "yes",
|
||||
"text": "Share it."
|
||||
},
|
||||
{
|
||||
"id": "no",
|
||||
"text": "Keep it local."
|
||||
}
|
||||
],
|
||||
"recommendation": "no",
|
||||
"depends": [
|
||||
"gamecult-chat:question:file-zone-audience"
|
||||
],
|
||||
"canonical": "{\"context\":\"</script> \u2028 &\",\"depends\":[\"gamecult-chat:question:file-zone-audience\"],\"options\":[{\"id\":\"yes\",\"text\":\"Share it.\"},{\"id\":\"no\",\"text\":\"Keep it local.\"}],\"recommendation\":\"no\",\"title\":\"q \\\" b \\\\ t \\t n \\n bell \\u0007 del \u007f\"}",
|
||||
"canonicalHex": "7B22636F6E74657874223A223C2F7363726970743E20E280A82026222C22646570656E6473223A5B2267616D6563756C742D636861743A7175657374696F6E3A66696C652D7A6F6E652D61756469656E6365225D2C226F7074696F6E73223A5B7B226964223A22796573222C2274657874223A2253686172652069742E227D2C7B226964223A226E6F222C2274657874223A224B656570206974206C6F63616C2E227D5D2C227265636F6D6D656E646174696F6E223A226E6F222C227469746C65223A2271205C222062205C5C2074205C74206E205C6E2062656C6C205C75303030372064656C207F227D",
|
||||
"sha256": "f2d5a09513ce728129f6ca13f7123aa75b2bb77541b1de8946f39239634b40fe"
|
||||
},
|
||||
{
|
||||
"name": "astral_option_id_and_text",
|
||||
"heimdall": null,
|
||||
"title": "Slot mark consent",
|
||||
"context": "Should a slot mark be shared?",
|
||||
"options": [
|
||||
{
|
||||
"id": "\ud83d\ude00",
|
||||
"text": "\ud834\udd1e"
|
||||
},
|
||||
{
|
||||
"id": "no",
|
||||
"text": "Keep it local."
|
||||
}
|
||||
],
|
||||
"recommendation": "no",
|
||||
"depends": [
|
||||
"gamecult-chat:question:file-zone-audience"
|
||||
],
|
||||
"canonical": "{\"context\":\"Should a slot mark be shared?\",\"depends\":[\"gamecult-chat:question:file-zone-audience\"],\"options\":[{\"id\":\"\ud83d\ude00\",\"text\":\"\ud834\udd1e\"},{\"id\":\"no\",\"text\":\"Keep it local.\"}],\"recommendation\":\"no\",\"title\":\"Slot mark consent\"}",
|
||||
"canonicalHex": "7B22636F6E74657874223A2253686F756C64206120736C6F74206D61726B206265207368617265643F222C22646570656E6473223A5B2267616D6563756C742D636861743A7175657374696F6E3A66696C652D7A6F6E652D61756469656E6365225D2C226F7074696F6E73223A5B7B226964223A22F09F9880222C2274657874223A22F09D849E227D2C7B226964223A226E6F222C2274657874223A224B656570206974206C6F63616C2E227D5D2C227265636F6D6D656E646174696F6E223A226E6F222C227469746C65223A22536C6F74206D61726B20636F6E73656E74227D",
|
||||
"sha256": "836fbfce16127132bae100aa773d328a85ad08d241ae9bf47ea7f84766762cac"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import { buildDesk, countOpen } from '../app/features/desk/buildDesk';
|
||||
import { deskFor, setDeskSource } from '../app/features/desk/source';
|
||||
import { unverifiedForks } from '../app/features/desk/optionsHash';
|
||||
import { demoDesk } from './deskForks';
|
||||
|
||||
describe('the demo desks', () => {
|
||||
|
|
@ -27,4 +28,8 @@ describe('the demo desks', () => {
|
|||
q.dependsOn.forEach((d) => d.questionId && expect(ids.has(d.questionId)).toBe(true))
|
||||
);
|
||||
});
|
||||
it('carry the hash of what they show, so the desk shows every seeded card', async () => {
|
||||
expect(await unverifiedForks(demoDesk('nibu')?.questions ?? [])).toEqual(new Set());
|
||||
expect(await unverifiedForks(demoDesk('eureka')?.questions ?? [])).toEqual(new Set());
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,16 +4,25 @@ import { DeskProjection, Question } from '../app/features/desk/feedback';
|
|||
|
||||
const DAY = 24 * 60 * 60 * 1000;
|
||||
|
||||
// Each question's options_hash over what it shows (optionsHash.ts); deskForks.test.ts fails if a seed is edited without it.
|
||||
const HASHES: Record<string, string> = {
|
||||
'sky-label': '727c7944919baf8953a0473bcbb38837c2e83c87d97a31a09ed6506a0e3b4028',
|
||||
'dusk-ink': 'e15b64509db522af68ad8904767edf0903a701809e50f1074c1c8b4b3660acae',
|
||||
'ridge-low-tier': '6edd4a08b6c86703d91b3f48bd697aca16450111573a8e391e3dfe3adc6cbf5f',
|
||||
'settled-window': 'b0dd0db3a37a256618d447ff8fb4067892b4f1f82d05a1e5bebf5563c447731c',
|
||||
};
|
||||
|
||||
const fork = (mind: string, label: string, daysAgo: number, over: Partial<Question>): Question => ({
|
||||
fork_id: `demo:question:${label}`,
|
||||
owner: mind,
|
||||
title: label,
|
||||
body: '',
|
||||
options: [],
|
||||
recommendation: '',
|
||||
dependsOn: [],
|
||||
askedAt: new Date(Date.now() - daysAgo * DAY).toISOString(),
|
||||
status: { state: 'open' },
|
||||
options_hash: `demo-${label}`,
|
||||
options_hash: HASHES[label],
|
||||
...over,
|
||||
});
|
||||
|
||||
|
|
@ -44,6 +53,12 @@ const SEEDS: Record<string, (now: number) => DeskProjection> = {
|
|||
}),
|
||||
fork('nibu', 'ridge-low-tier', 40, {
|
||||
title: 'Keep the ridge scene at the low tier?',
|
||||
body: 'The ridge costs a little on older phones.',
|
||||
options: [
|
||||
{ id: 'keep', text: 'Keep it' },
|
||||
{ id: 'drop', text: 'Drop it' },
|
||||
],
|
||||
recommendation: 'keep',
|
||||
status: { state: 'answered', rulingId: 'demo:ruling:ridge-low-tier' },
|
||||
}),
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in a new issue