@mostra/conformance 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,7 @@ import { INTERACTION_SCENARIOS } from "./interaction.ts";
9
9
  import { PORT_SCENARIOS } from "./ports.ts";
10
10
  import { REMOTE_SCENARIOS } from "./remote.ts";
11
11
  import { SESSION_SCENARIOS } from "./session.ts";
12
+ import { TEAM_SCENARIOS } from "./team.ts";
12
13
  import { VIEWING_SCENARIOS } from "./viewing.ts";
13
14
 
14
15
  /** Every scenario. */
@@ -19,4 +20,5 @@ export const SCENARIOS: readonly Scenario[] = [
19
20
  ...PORT_SCENARIOS,
20
21
  ...VIEWING_SCENARIOS,
21
22
  ...REMOTE_SCENARIOS,
23
+ ...TEAM_SCENARIOS,
22
24
  ];
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Teams (WP-31, D168): expected respondents with personal links through the host's own client,
3
+ * each respondent's status, the roster's durable events, and the `submitted:all` and
4
+ * `submitted:<N>` waits under `once` per viewer and `epochs`, with each answer delivered to the
5
+ * host (CO-01, CO-02, CO-03).
6
+ */
7
+ import { FORM } from "../fixtures.ts";
8
+ import { type Scenario, same } from "../scenario.ts";
9
+ import { Viewer } from "../viewer.ts";
10
+
11
+ interface RosterAnswer {
12
+ readonly roster: {
13
+ readonly round: number;
14
+ readonly complete: boolean;
15
+ readonly respondents: readonly { readonly ref: string; readonly status: string }[];
16
+ };
17
+ readonly links: readonly { readonly ref: string; readonly link: { readonly url: string } }[];
18
+ }
19
+
20
+ const PEOPLE = [
21
+ { ref: "ada@example.com", name: "Ada" },
22
+ { ref: "grace@example.com", name: "Grace" },
23
+ { ref: "alan@example.com", name: "Alan" },
24
+ ];
25
+
26
+ /** Answers and submits on whichever channel the view allows. */
27
+ async function answerAndSubmit(viewer: Viewer, fields: Record<string, unknown>) {
28
+ return viewer.answer(
29
+ fields,
30
+ viewer.ticket.submitChannels.includes("artifact") ? "artifact" : "shell",
31
+ );
32
+ }
33
+
34
+ /** CO-01, CO-03: a roster through the host's client; each link acts as its respondent. */
35
+ export const roster: Scenario = {
36
+ id: "team.roster",
37
+ title:
38
+ "roster/add gives each expected respondent a personal link that acts as them, again keeps it; roster/get reports each one's status; roster changes are durable events",
39
+ covers: ["HO-05", "CO-01", "CO-03"],
40
+ async run(context) {
41
+ await context.start();
42
+ const receipt = await context.published(FORM, {
43
+ policy: { policy: "once", scope: "per-viewer" },
44
+ });
45
+ const artifact = { artifactId: receipt.artifactId };
46
+ const added = await context.host.call<RosterAnswer>("roster/add", {
47
+ artifact,
48
+ respondents: PEOPLE,
49
+ });
50
+ same(added.links.length, 3, "the personal links roster/add gives three respondents");
51
+ const again = await context.host.call<RosterAnswer>("roster/add", {
52
+ artifact,
53
+ respondents: PEOPLE,
54
+ });
55
+ same(
56
+ again.links.map((entry) => entry.link.url).join(" "),
57
+ added.links.map((entry) => entry.link.url).join(" "),
58
+ "the links adding the same respondents again gives",
59
+ );
60
+ const viewers: Viewer[] = [];
61
+ for (const entry of added.links) viewers.push(await Viewer.open(entry.link.url));
62
+ const [ada] = viewers as [Viewer, ...Viewer[]];
63
+ same((await answerAndSubmit(ada, { name: "Ada" })).status, 200, "Ada's submit");
64
+ const read = await context.host.call<RosterAnswer["roster"]>("roster/get", { artifact });
65
+ same(
66
+ read.respondents.map((one) => `${one.ref}=${one.status}`).join(" "),
67
+ "ada@example.com=submitted grace@example.com=drafting alan@example.com=drafting",
68
+ "each respondent's status: Ada submitted, the others opened their links",
69
+ );
70
+ const results = await context.results(receipt.artifactId);
71
+ same(results.submission.viewer.name, "Ada", "the submission's viewer is the respondent");
72
+ const events = await context.events({ artifacts: [receipt.artifactId], types: ["roster.*"] });
73
+ same(
74
+ events.events.map((event) => event.type).join(" "),
75
+ "roster.changed",
76
+ "the roster's events: one change, adding again changed nothing",
77
+ );
78
+ },
79
+ };
80
+
81
+ /** CO-02: everyone's answer, under once per viewer and epochs, each delivered to the host. */
82
+ export const waits: Scenario = {
83
+ id: "team.waits",
84
+ title:
85
+ "submitted:all holds exactly when the last expected respondent submits (roster.completed), once per round under epochs; submitted:<N> at the N-th; every answer reaches the host",
86
+ covers: ["HO-05", "CO-02", "IN-12"],
87
+ async run(context) {
88
+ await context.start();
89
+ for (const policy of [{ policy: "once", scope: "per-viewer" }, { policy: "epochs" }]) {
90
+ const receipt = await context.published(FORM, { policy });
91
+ const artifact = { artifactId: receipt.artifactId };
92
+ const added = await context.host.call<RosterAnswer>("roster/add", {
93
+ artifact,
94
+ respondents: PEOPLE,
95
+ });
96
+ const viewers: Viewer[] = [];
97
+ for (const entry of added.links) viewers.push(await Viewer.open(entry.link.url));
98
+ const start = await context.host.call<{ cursor: string }>("wait", {
99
+ artifact,
100
+ until: "submitted:all",
101
+ timeoutMs: 0,
102
+ });
103
+ same(
104
+ (start as { status?: string }).status,
105
+ "still_waiting",
106
+ `${policy.policy}: before anyone`,
107
+ );
108
+ const all = context.host.call<{ status: string; event: { type: string }; cursor: string }>(
109
+ "wait",
110
+ { artifact, until: "submitted:all", after: start.cursor, timeoutMs: 60_000 },
111
+ );
112
+ for (const [index, viewer] of viewers.entries()) {
113
+ same(
114
+ (await answerAndSubmit(viewer, { name: PEOPLE[index]?.name })).status,
115
+ 200,
116
+ `${policy.policy}: ${PEOPLE[index]?.name}'s submit`,
117
+ );
118
+ if (index === 1) {
119
+ const two = await context.host.call<{ status: string }>("wait", {
120
+ artifact,
121
+ until: "submitted:2",
122
+ after: start.cursor,
123
+ timeoutMs: 0,
124
+ });
125
+ same(two.status, "satisfied", `${policy.policy}: submitted:2 at the second answer`);
126
+ const early = await context.host.call<{ status: string }>("wait", {
127
+ artifact,
128
+ until: "submitted:all",
129
+ after: start.cursor,
130
+ timeoutMs: 0,
131
+ });
132
+ same(early.status, "still_waiting", `${policy.policy}: submitted:all before the last`);
133
+ }
134
+ }
135
+ const done = await all;
136
+ same(done.status, "satisfied", `${policy.policy}: submitted:all at the last answer`);
137
+ same(done.event.type, "roster.completed", `${policy.policy}: the event that satisfies it`);
138
+ if (policy.policy === "epochs") {
139
+ const next = await context.host.call<{ status: string }>("wait", {
140
+ artifact,
141
+ until: "submitted:all",
142
+ after: done.cursor,
143
+ timeoutMs: 0,
144
+ });
145
+ same(next.status, "still_waiting", "epochs: the next round waits for everyone again");
146
+ const round = await context.host.call<RosterAnswer["roster"]>("roster/get", { artifact });
147
+ same(round.round, 2, "epochs: the roster's round after everyone answered");
148
+ }
149
+ }
150
+ // Every answer of both artifacts reaches the host that takes submissions.
151
+ if (context.host.serves("submissions")) {
152
+ await context.eventually(
153
+ "every answer of both rosters in the host's store",
154
+ async () => (await context.store()).deliveries.length >= 6,
155
+ );
156
+ }
157
+ },
158
+ };
159
+
160
+ /** The team scenarios. */
161
+ export const TEAM_SCENARIOS: readonly Scenario[] = [roster, waits];