@bongos/core 1.24.26 → 1.24.28

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.
Files changed (109) hide show
  1. package/.bongos-core.json +164 -109
  2. package/docs/adr/0307-autobongos-a-deterministic-supervisor-and-agentic-workers.md +12 -0
  3. package/docs/copy-inventory.md +242 -223
  4. package/docs/copy-registry.json +559 -358
  5. package/docs/module-api-changelog.md +4 -0
  6. package/docs/page-inventory.json +18 -6
  7. package/docs/page-readings.json +4399 -4315
  8. package/docs/recipes/ui-look-before-you-ship.md +1 -0
  9. package/modules/autonomy/fence.js +16 -1
  10. package/modules/government/protected-surfaces.json +2 -0
  11. package/modules/hall-ui/public/ai-studio.html +1 -1
  12. package/modules/hall-ui/public/atlas.html +1 -1
  13. package/modules/hall-ui/public/blockers.html +1 -1
  14. package/modules/hall-ui/public/board-room.html +1 -1
  15. package/modules/hall-ui/public/city.html +1 -1
  16. package/modules/hall-ui/public/collab.html +1 -1
  17. package/modules/hall-ui/public/commands.html +1 -1
  18. package/modules/hall-ui/public/copy-desk.html +1 -1
  19. package/modules/hall-ui/public/core-move-notice.js +9 -6
  20. package/modules/hall-ui/public/deploy-handoff.js +203 -0
  21. package/modules/hall-ui/public/deploy.html +4 -2
  22. package/modules/hall-ui/public/deploy.js +7 -1
  23. package/modules/hall-ui/public/diagrams.html +1 -1
  24. package/modules/hall-ui/public/drachmae.html +1 -1
  25. package/modules/hall-ui/public/fleet.html +1 -1
  26. package/modules/hall-ui/public/gate.html +1 -1
  27. package/modules/hall-ui/public/goal-map.html +1 -1
  28. package/modules/hall-ui/public/goals.html +1 -1
  29. package/modules/hall-ui/public/government.html +1 -1
  30. package/modules/hall-ui/public/idea.html +1 -1
  31. package/modules/hall-ui/public/ideas.html +1 -1
  32. package/modules/hall-ui/public/index.html +1 -1
  33. package/modules/hall-ui/public/market-watch-item.html +1 -1
  34. package/modules/hall-ui/public/market-watch-rules.html +1 -1
  35. package/modules/hall-ui/public/market-watch-settings.html +1 -1
  36. package/modules/hall-ui/public/market-watch.html +1 -1
  37. package/modules/hall-ui/public/modules.html +1 -1
  38. package/modules/hall-ui/public/my-agents.css +72 -1
  39. package/modules/hall-ui/public/my-agents.html +31 -7
  40. package/modules/hall-ui/public/my-agents.js +63 -54
  41. package/modules/hall-ui/public/my-agents.states.json +18 -0
  42. package/modules/hall-ui/public/primer.html +1 -1
  43. package/modules/hall-ui/public/profile.html +1 -1
  44. package/modules/hall-ui/public/project-settings.html +1 -1
  45. package/modules/hall-ui/public/ranks.html +1 -1
  46. package/modules/hall-ui/public/roadmap.html +1 -1
  47. package/modules/hall-ui/public/roster.html +1 -1
  48. package/modules/hall-ui/public/sessions.html +1 -1
  49. package/modules/hall-ui/public/settings-software-update.js +22 -8
  50. package/modules/hall-ui/public/settings.css +2 -132
  51. package/modules/hall-ui/public/settings.html +15 -53
  52. package/modules/hall-ui/public/shell.js +25 -73
  53. package/modules/hall-ui/public/speciality-tools.css +140 -0
  54. package/modules/hall-ui/public/{settings-specialities.js → speciality-tools.js} +83 -6
  55. package/modules/hall-ui/public/street.html +1 -1
  56. package/modules/hall-ui/public/studio.html +1 -1
  57. package/modules/hall-ui/public/style.css +119 -39
  58. package/modules/hall-ui/public/task.html +1 -1
  59. package/modules/hall-ui/public/thinking.html +1 -1
  60. package/modules/hall-ui/public/tweak-editor.html +1 -1
  61. package/modules/hall-ui/public/update-pill.js +623 -0
  62. package/modules/hall-ui/public/watch.html +1 -1
  63. package/modules/hall-ui/public/work.html +1 -1
  64. package/modules/hall-ui/records/my-agents.md +4 -2
  65. package/modules/hall-ui/records/panel-family.md +2 -0
  66. package/modules/hall-ui/records/update-pill.md +12 -0
  67. package/modules/lifecycle/github-push.js +1 -0
  68. package/modules/lifecycle/routes/tasks.js +2 -2
  69. package/modules/lifecycle/runner-self-guard.js +122 -0
  70. package/modules/lifecycle/runner-self.js +154 -0
  71. package/modules/public-landing/public/account.html +3 -3
  72. package/modules/public-landing/public/assets/cosmos.css +45 -0
  73. package/modules/public-landing/public/community.html +4 -4
  74. package/modules/public-landing/public/connections.html +1 -1
  75. package/modules/public-landing/public/guild.html +1 -1
  76. package/modules/public-landing/public/invitations.html +4 -4
  77. package/modules/public-landing/public/projects.html +26 -26
  78. package/modules/status-ui/public/index.html +2 -2
  79. package/modules/status-ui/public/index.states.json +12 -0
  80. package/modules/status-ui/public/status.js +10 -2
  81. package/modules/status-ui/public/style.css +57 -0
  82. package/modules/ui-design/kit/README.md +1 -1
  83. package/modules/ui-design/kit/serve.js +8 -1
  84. package/package-lock.json +2 -2
  85. package/package.json +1 -1
  86. package/release-notes.json +20 -0
  87. package/scripts/bongos/autobongos-loop.js +4 -0
  88. package/scripts/bongos/autobongos-run.js +21 -4
  89. package/scripts/bongos/autobongos-tweak-lane.js +5 -3
  90. package/scripts/bongos/ship-flow.js +20 -0
  91. package/scripts/hall-preview/server.js +4 -0
  92. package/src/module-api.js +1 -1
  93. package/tests/autobongos_host_access.mjs +5 -3
  94. package/tests/autobongos_self_modification.mjs +420 -0
  95. package/tests/core_update_banner.mjs +6 -92
  96. package/tests/core_upgrade_owner_door.mjs +4 -56
  97. package/tests/deploy_handoff.mjs +206 -0
  98. package/tests/government_protected_surfaces.mjs +15 -0
  99. package/tests/hall_loading.mjs +3 -1
  100. package/tests/hall_my_agents.mjs +104 -2
  101. package/tests/helpers.mjs +161 -0
  102. package/tests/hub_connections_page.mjs +1 -1
  103. package/tests/hub_invitations_page.mjs +1 -1
  104. package/tests/loading_mark.mjs +203 -0
  105. package/tests/nav_permission_atoms.mjs +3 -2
  106. package/tests/software_update.mjs +6 -2
  107. package/tests/speciality_offer_ui.mjs +182 -149
  108. package/tests/speciality_walkthrough_ui.mjs +180 -161
  109. package/tests/update_pill.mjs +431 -0
@@ -1,5 +1,6 @@
1
- // tests/speciality_walkthrough_ui.mjs — the skills walkthrough a person is taken
2
- // through when they adopt a speciality (task 1004073, part 2 of 3 of ADR 0310).
1
+ // tests/speciality_walkthrough_ui.mjs — the ADOPTER's side of the speciality
2
+ // tools: taking one on, the skills walkthrough it opens, and stopping it (task
3
+ // 1004073, part 2 of 3 of ADR 0310; on My agents too since task 1005052).
3
4
  //
4
5
  // The owner's ruling: an adopted speciality's skills start OFF, "and you should
5
6
  // walk through what comes with each, people need to learn the system". The task
@@ -9,21 +10,19 @@
9
10
  // every step, no control that decides without the person seeing each skill, and
10
11
  // nothing written until the recap is saved.
11
12
  //
12
- // This EXECUTES the real modules/hall-ui/public/settings-specialities.js in a vm
13
- // under a minimal DOM stub (the tests/goal_criterion_confirm_ui.mjs precedent —
14
- // there is no jsdom here), against a fake API, and drives real clicks through the
15
- // delegated handler the page wires.
13
+ // THE SAFETY STEP. A speciality someone else wrote puts their prose into your
14
+ // sessions, so its full instructions are on the card, open, before the control
15
+ // that adopts it — pinned below on both pages.
16
+ //
17
+ // TWO PAGES, ONE COMPONENT (task 1005052). modules/hall-ui/public/speciality-tools.js
18
+ // is mounted by Settings and by My agents. Every case runs once per page, booted
19
+ // on THAT page's own markup (tests/helpers.mjs bootSpecialityTools), so a host
20
+ // lost from either page fails that page's run.
16
21
  //
17
22
  // Run: node tests/speciality_walkthrough_ui.mjs
18
23
  import assert from 'node:assert/strict';
19
- import fs from 'node:fs';
20
- import path from 'node:path';
21
- import vm from 'node:vm';
22
- import { fileURLToPath } from 'node:url';
23
- import { makeRunner } from './helpers.mjs';
24
-
25
- const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
26
- const SRC = fs.readFileSync(path.join(ROOT, 'modules/hall-ui/public/settings-specialities.js'), 'utf8');
24
+ import { makeRunner, bootSpecialityTools, SPECIALITY_PAGES } from './helpers.mjs';
25
+
27
26
  const { test, summary } = makeRunner();
28
27
 
29
28
  const explained = (name, extra = {}) => ({
@@ -56,163 +55,183 @@ const SKILLS_BODY = {
56
55
  ],
57
56
  };
58
57
 
59
- // Boot the page script and return a handle to drive it.
60
- async function boot({ catalog = [speciality()], skillsBody = SKILLS_BODY } = {}) {
61
- const requests = [];
62
- const toasts = [];
63
- const els = new Map();
64
- const handlers = new Map();
65
- const makeEl = (id) => ({
66
- id, hidden: id === 'specialities-scroll', innerHTML: '', textContent: '', elements: {},
67
- addEventListener(type, fn) { handlers.set(`${id}:${type}`, fn); },
68
- });
69
- for (const id of ['specialities-scroll', 'specialities-rows', 'speciality-suggestions', 'specialities-status']) els.set(id, makeEl(id));
70
- let focused = null;
71
-
72
- const fetch = async (url, opts = {}) => {
73
- const method = opts.method || 'GET';
74
- const p = url.replace('/api/bongos', '');
75
- requests.push({ method, path: p, body: opts.body ? JSON.parse(opts.body) : undefined });
76
- let body = {};
77
- if (method === 'GET' && p === '/specialities') body = { specialities: catalog };
78
- else if (method === 'GET' && p === '/me/specialities') body = { adoptions: [] };
79
- else if (method === 'GET' && p === '/specialities/offered') body = { suggestions: [] };
80
- else if (method === 'GET' && /\/skills$/.test(p)) body = skillsBody;
81
- else if (method === 'POST' && /\/adopt$/.test(p)) body = { adoption: { active: true } };
82
- else if (method === 'PUT' && /\/skills$/.test(p)) body = { adoption: { enabled_skills: JSON.parse(opts.body).enabled_skills } };
83
- return { ok: true, status: 200, json: async () => body };
84
- };
85
-
86
- const document = {
87
- readyState: 'complete',
88
- getElementById: (id) => els.get(id) || null,
89
- addEventListener() {},
90
- querySelector: (sel) => (sel.includes('data-walk-focus') ? { focus() { focused = 'walk-heading'; } } : null),
91
- };
92
- const window = {
93
- OTB: {
94
- escapeHtml: (s) => String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;'),
95
- $: () => null,
96
- toast: (m) => toasts.push(m),
97
- roleAxisLabel: () => 'Role',
98
- },
99
- location: { assign() {} },
100
- };
101
- vm.runInNewContext(SRC, { window, document, fetch, JSON, Promise, Map, Set, String, Number, Array, Object, Math, RegExp, console });
102
- const settle = () => new Promise((r) => setTimeout(r, 0));
103
- for (let i = 0; i < 5; i++) await settle();
104
-
105
- const rows = els.get('specialities-rows');
106
- // A click through the delegated handler, on the first button whose attribute matches.
107
- async function click(attr, value) {
108
- const re = new RegExp(`<button[^>]*${attr}="${value}"[^>]*>`);
109
- const tag = re.exec(rows.innerHTML);
110
- assert.ok(tag, `no ${attr}="${value}" button in:\n${rows.innerHTML}`);
111
- const dataset = {};
112
- for (const [, k, v] of tag[0].matchAll(/data-([a-z]+)="([^"]*)"/g)) dataset[k] = v;
113
- const btn = { dataset };
114
- const target = { closest: (sel) => (sel === `button[${attr}]` ? btn : null) };
115
- handlers.get('specialities-rows:click')({ target });
116
- for (let i = 0; i < 6; i++) await settle();
117
- }
118
- const text = () => rows.innerHTML.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ');
119
- return { els, rows, requests, toasts, click, text, focused: () => focused };
58
+ async function boot(page, { catalog = [speciality()], skillsBody = SKILLS_BODY, ...rest } = {}) {
59
+ const h = bootSpecialityTools({ page, catalog, skills: { 9: skillsBody }, ...rest });
60
+ await h.ready();
61
+ return h;
120
62
  }
63
+ const ROWS = '#specialities-rows';
64
+ const writes = (h) => h.writes();
65
+ const text = (h) => h.text('specialities-rows');
66
+
67
+ for (const page of SPECIALITY_PAGES) {
68
+ await test(`${page}: the specialities panel is revealed once its reads answer — it shipped hidden and nothing ever showed it`, async () => {
69
+ const h = await boot(page);
70
+ assert.equal(h.el('specialities-scroll').hidden, false);
71
+ });
121
72
 
122
- const writes = (h) => h.requests.filter((r) => r.method !== 'GET');
73
+ await test(`${page}: adopting a speciality that offers skills opens the walkthrough on the FIRST skill, with nothing written yet`, async () => {
74
+ const h = await boot(page);
75
+ await h.click(`${ROWS} button[data-act="adopt"]`);
76
+ assert.ok(h.requests.some((r) => r.method === 'GET' && r.path === '/specialities/9/skills'), 'the walkthrough read its skills');
77
+ assert.match(text(h), /Skill 1 of 3 in Economics/, 'only INSTALLED skills are steps');
78
+ assert.ok(h.focused() && 'data-walk-focus' in h.focused().attrs, 'focus moves to the step, not left on a button that is gone');
79
+ assert.deepEqual(writes(h).map((r) => r.path), ['/specialities/9/adopt'], 'no enabled set was written by adopting');
80
+ });
123
81
 
124
- await test('the specialities panel is revealed once its reads answer — it shipped hidden and nothing ever showed it', async () => {
125
- const h = await boot();
126
- assert.equal(h.els.get('specialities-scroll').hidden, false);
127
- });
82
+ await test(`${page}: it is not a page of checkboxes: one skill per step, and no control decides for several at once`, async () => {
83
+ const h = await boot(page);
84
+ await h.click(`${ROWS} button[data-act="adopt"]`);
85
+ assert.ok(!/type="checkbox"/.test(h.html('specialities-rows')), 'no checkbox anywhere in the walkthrough');
86
+ assert.ok(!/(turn|enable|select) (them )?all/i.test(text(h)), 'no "turn them all on"');
87
+ assert.ok(text(h).includes('recall') && !text(h).includes('status does its one thing'), 'the next skill is not shown yet');
88
+ });
128
89
 
129
- await test('adopting a speciality that offers skills opens the walkthrough on the FIRST skill, with nothing written yet', async () => {
130
- const h = await boot();
131
- await h.click('data-act', 'adopt');
132
- assert.ok(h.requests.some((r) => r.method === 'GET' && r.path === '/specialities/9/skills'), 'the walkthrough read its skills');
133
- assert.match(h.text(), /Skill 1 of 3 in Economics/, 'only INSTALLED skills are steps');
134
- assert.equal(h.focused(), 'walk-heading', 'focus moves to the step, not left on a button that is gone');
135
- assert.deepEqual(writes(h).map((r) => r.path), ['/specialities/9/adopt'], 'no enabled set was written by adopting');
136
- });
90
+ await test(`${page}: every step answers what it does, when to reach for it, and what it costs`, async () => {
91
+ const h = await boot(page);
92
+ await h.click(`${ROWS} button[data-act="adopt"]`);
93
+ for (let step = 0; step < 3; step++) {
94
+ for (const q of ['What it does', 'When to reach for it', 'What it costs']) assert.ok(text(h).includes(q), `step ${step + 1} is missing "${q}"`);
95
+ await h.click(`${ROWS} button[data-walk="off"]`);
96
+ }
97
+ });
137
98
 
138
- await test('it is not a page of checkboxes: one skill per step, and no control decides for several at once', async () => {
139
- const h = await boot();
140
- await h.click('data-act', 'adopt');
141
- assert.ok(!/type="checkbox"/.test(h.rows.innerHTML), 'no checkbox anywhere in the walkthrough');
142
- assert.ok(!/(turn|enable|select) (them )?all/i.test(h.text()), 'no "turn them all on"');
143
- assert.ok(h.text().includes('recall') && !h.text().includes('status does its one thing'), 'the next skill is not shown yet');
144
- });
99
+ await test(`${page}: a rank-gated skill says so BEFORE the choice — turning it on grants nothing`, async () => {
100
+ const h = await boot(page);
101
+ await h.click(`${ROWS} button[data-act="adopt"]`);
102
+ await h.click(`${ROWS} button[data-walk="off"]`);
103
+ await h.click(`${ROWS} button[data-walk="off"]`);
104
+ const t = text(h);
105
+ assert.match(t, /Skill 3 of 3/);
106
+ assert.match(t, /Metic rank or above.*does not change that/);
107
+ assert.match(t, /What it needs on your machine gh/);
108
+ });
145
109
 
146
- await test('every step answers what it does, when to reach for it, and what it costs', async () => {
147
- const h = await boot();
148
- await h.click('data-act', 'adopt');
149
- for (let step = 0; step < 3; step++) {
150
- const t = h.text();
151
- for (const q of ['What it does', 'When to reach for it', 'What it costs']) assert.ok(t.includes(q), `step ${step + 1} is missing "${q}"`);
152
- await h.click('data-walk', 'off');
153
- }
154
- });
110
+ await test(`${page}: the recap names every skill with what it does and the choice made, then saves exactly the ones turned on`, async () => {
111
+ const h = await boot(page);
112
+ await h.click(`${ROWS} button[data-act="adopt"]`);
113
+ await h.click(`${ROWS} button[data-walk="on"]`);
114
+ await h.click(`${ROWS} button[data-walk="off"]`);
115
+ await h.click(`${ROWS} button[data-walk="on"]`);
116
+ const t = text(h);
117
+ assert.match(t, /Your choices for Economics/);
118
+ assert.match(t, /2 of 3 turned on/);
119
+ for (const n of ['recall', 'status', 'goal-review']) assert.ok(t.includes(`${n} does its one thing.`), `the recap restates what ${n} does`);
120
+ assert.ok(!t.includes('And a second sentence'), 'one line each, not the whole description again');
121
+ assert.match(t, /no longer on this project.*gone/, 'an offered skill removed since is named, not offered');
122
+ assert.equal(writes(h).length, 1, 'still nothing written before Save');
123
+ await h.click(`${ROWS} button[data-walk="save"]`);
124
+ const put = writes(h).find((r) => r.method === 'PUT');
125
+ assert.ok(put, 'Save wrote the set');
126
+ assert.equal(put.path, '/specialities/9/skills');
127
+ assert.deepEqual(put.body, { enabled_skills: ['recall', 'goal-review'] });
128
+ assert.ok(h.toasts.some((m) => /2 of 3/.test(m)));
129
+ });
155
130
 
156
- await test('a rank-gated skill says so BEFORE the choice — turning it on grants nothing', async () => {
157
- const h = await boot();
158
- await h.click('data-act', 'adopt');
159
- await h.click('data-walk', 'off');
160
- await h.click('data-walk', 'off');
161
- const t = h.text();
162
- assert.match(t, /Skill 3 of 3/);
163
- assert.match(t, /Metic rank or above.*does not change that/);
164
- assert.match(t, /What it needs on your machine gh/);
165
- });
131
+ await test(`${page}: Back revisits a decision and the new choice is the one saved`, async () => {
132
+ const h = await boot(page);
133
+ await h.click(`${ROWS} button[data-act="adopt"]`);
134
+ await h.click(`${ROWS} button[data-walk="on"]`);
135
+ await h.click(`${ROWS} button[data-walk="back"]`);
136
+ assert.match(text(h), /Skill 1 of 3/);
137
+ assert.match(h.html('specialities-rows'), /data-walk="on" aria-pressed="true"/, 'the earlier choice shows when you step back to it');
138
+ await h.click(`${ROWS} button[data-walk="off"]`);
139
+ await h.click(`${ROWS} button[data-walk="off"]`);
140
+ await h.click(`${ROWS} button[data-walk="off"]`);
141
+ await h.click(`${ROWS} button[data-walk="save"]`);
142
+ assert.deepEqual(writes(h).find((r) => r.method === 'PUT').body, { enabled_skills: [] });
143
+ });
166
144
 
167
- await test('the recap names every skill with what it does and the choice made, then saves exactly the ones turned on', async () => {
168
- const h = await boot();
169
- await h.click('data-act', 'adopt');
170
- await h.click('data-walk', 'on');
171
- await h.click('data-walk', 'off');
172
- await h.click('data-walk', 'on');
173
- const t = h.text();
174
- assert.match(t, /Your choices for Economics/);
175
- assert.match(t, /2 of 3 turned on/);
176
- for (const n of ['recall', 'status', 'goal-review']) assert.ok(t.includes(`${n} does its one thing.`), `the recap restates what ${n} does`);
177
- assert.ok(!t.includes('And a second sentence'), 'one line each, not the whole description again');
178
- assert.match(t, /no longer on this project.*gone/, 'an offered skill removed since is named, not offered');
179
- assert.equal(writes(h).length, 1, 'still nothing written before Save');
180
- await h.click('data-walk', 'save');
181
- const put = writes(h).find((r) => r.method === 'PUT');
182
- assert.ok(put, 'Save wrote the set');
183
- assert.equal(put.path, '/specialities/9/skills');
184
- assert.deepEqual(put.body, { enabled_skills: ['recall', 'goal-review'] });
185
- assert.ok(h.toasts.some((m) => /2 of 3/.test(m)));
186
- });
145
+ await test(`${page}: finishing later writes nothing, so every skill stays off — the default the ruling asked for`, async () => {
146
+ const h = await boot(page);
147
+ await h.click(`${ROWS} button[data-act="adopt"]`);
148
+ await h.click(`${ROWS} button[data-walk="on"]`);
149
+ await h.click(`${ROWS} button[data-walk="close"]`);
150
+ assert.ok(!/skill-walk/.test(h.html('specialities-rows')), 'the walkthrough closed');
151
+ assert.ok(!writes(h).some((r) => r.method === 'PUT'), 'a half-finished walk saves nothing');
152
+ });
187
153
 
188
- await test('Back revisits a decision and the new choice is the one saved', async () => {
189
- const h = await boot();
190
- await h.click('data-act', 'adopt');
191
- await h.click('data-walk', 'on');
192
- await h.click('data-walk', 'back');
193
- assert.match(h.text(), /Skill 1 of 3/);
194
- assert.match(h.rows.innerHTML, /data-walk="on" aria-pressed="true"/, 'the earlier choice shows when you step back to it');
195
- await h.click('data-walk', 'off');
196
- await h.click('data-walk', 'off');
197
- await h.click('data-walk', 'off');
198
- await h.click('data-walk', 'save');
199
- assert.deepEqual(writes(h).find((r) => r.method === 'PUT').body, { enabled_skills: [] });
200
- });
154
+ await test(`${page}: a speciality that offers no skills adopts without a walkthrough`, async () => {
155
+ const h = await boot(page, { catalog: [speciality({ skills: [] })] });
156
+ await h.click(`${ROWS} button[data-act="adopt"]`);
157
+ assert.ok(!h.requests.some((r) => /\/skills$/.test(r.path)), 'no skills read for a speciality with none');
158
+ assert.ok(!/skill-walk/.test(h.html('specialities-rows')));
159
+ });
201
160
 
202
- await test('finishing later writes nothing, so every skill stays off — the default the ruling asked for', async () => {
203
- const h = await boot();
204
- await h.click('data-act', 'adopt');
205
- await h.click('data-walk', 'on');
206
- await h.click('data-walk', 'close');
207
- assert.ok(!/skill-walk/.test(h.rows.innerHTML), 'the walkthrough closed');
208
- assert.ok(!writes(h).some((r) => r.method === 'PUT'), 'a half-finished walk saves nothing');
209
- });
161
+ // ---- the safety step, and the rest of the adopter's tools (task 1005052) ----
162
+
163
+ await test(`${page}: SAFETY — someone else's speciality shows its full instructions, open, in the same card as the only control that adopts it`, async () => {
164
+ const contract = 'Argue from mechanism, not vibes.\nAlways name the assumption a number rests on.';
165
+ const h = await boot(page, { catalog: [speciality({ contract_md: contract })], suggestions: [speciality({ id: 21, name: 'Rates', contract_md: contract })] });
166
+ for (const host of ['specialities-rows', 'speciality-suggestions']) {
167
+ const card = h.find(`#${host} li[data-id]`);
168
+ assert.ok(card, `${host}: the speciality has a card`);
169
+ const details = card.querySelector('details');
170
+ assert.ok(details && details.open, `${host}: its instructions are OPEN, not folded behind a summary`);
171
+ assert.equal(card.querySelector('pre').textContent, contract, `${host}: the whole instruction, word for word`);
172
+ assert.match(card.querySelector('summary').textContent, /written by someone else/, `${host}: and whose they are`);
173
+ assert.match(details.textContent, /You did not write this\. Read it before using the speciality/);
174
+ assert.ok(card.querySelector('button[data-act="adopt"]'), `${host}: the adopt control is in that same card`);
175
+ }
176
+ assert.equal(h.find('button[data-adopt]'), null, 'no other control adopts it');
177
+ });
210
178
 
211
- await test('a speciality that offers no skills adopts without a walkthrough', async () => {
212
- const h = await boot({ catalog: [speciality({ skills: [] })] });
213
- await h.click('data-act', 'adopt');
214
- assert.ok(!h.requests.some((r) => /\/skills$/.test(r.path)), 'no skills read for a speciality with none');
215
- assert.ok(!/skill-walk/.test(h.rows.innerHTML));
216
- });
179
+ await test(`${page}: a speciality you use can be stopped: one POST /abandon, and the card offers it again`, async () => {
180
+ const h = await boot(page, { adoptions: [{ id: 9, active: true, enabled_skills: ['recall'] }] });
181
+ assert.match(text(h), /active/, 'the card says it is in use');
182
+ assert.match(text(h), /offers 4 skills, 1 on for you/, 'and how many of its skills are on');
183
+ assert.equal(h.find(`${ROWS} button[data-act="adopt"]`), null, 'in use: no "Use this"');
184
+ await h.click(`${ROWS} button[data-act="abandon"]`);
185
+ assert.deepEqual(writes(h).map((r) => `${r.method} ${r.path}`), ['POST /specialities/9/abandon']);
186
+ assert.ok(h.toasts.includes('Stopped using it.'));
187
+ assert.ok(h.find(`${ROWS} button[data-act="adopt"]`), 'stopped: it can be taken on again');
188
+ assert.equal(h.find(`${ROWS} button[data-act="abandon"]`), null);
189
+ });
190
+
191
+ await test(`${page}: stopping a speciality closes its walkthrough if it was open`, async () => {
192
+ const h = await boot(page, { adoptions: [{ id: 9, active: true, enabled_skills: [] }] });
193
+ await h.click(`${ROWS} button[data-act="walk"]`);
194
+ assert.match(h.html('specialities-rows'), /skill-walk/);
195
+ await h.click(`${ROWS} button[data-act="abandon"]`);
196
+ assert.ok(!/skill-walk/.test(h.html('specialities-rows')), 'no walkthrough for a speciality you stopped using');
197
+ });
198
+
199
+ await test(`${page}: "Choose its skills" reopens the walkthrough for one you use, and says which are on now`, async () => {
200
+ const h = await boot(page, { adoptions: [{ id: 9, active: true, enabled_skills: ['recall'] }], skillsBody: { ...SKILLS_BODY, enabled: ['recall'] } });
201
+ await h.click(`${ROWS} button[data-act="walk"]`);
202
+ assert.match(text(h), /Skill 1 of 3 in Economics/);
203
+ assert.match(text(h), /You have this one on at the moment/);
204
+ assert.equal(writes(h).length, 0, 'opening it writes nothing');
205
+ });
206
+
207
+ await test(`${page}: a suggestion adopts through the same act as the catalogue`, async () => {
208
+ const h = await boot(page, { suggestions: [speciality({ id: 21, name: 'Rates', skills: [] })] });
209
+ assert.match(h.text('speciality-suggestions'), /Suggested for you.*Rates/);
210
+ await h.click('#speciality-suggestions button[data-act="adopt"]');
211
+ assert.deepEqual(writes(h).map((r) => `${r.method} ${r.path}`), ['POST /specialities/21/adopt']);
212
+ });
213
+
214
+ await test(`${page}: adopting, stopping and saving its skills each tell the rest of the page, so what a session reads can be re-read`, async () => {
215
+ const h = await boot(page);
216
+ await h.click(`${ROWS} button[data-act="adopt"]`);
217
+ assert.deepEqual(h.events, ['otb:specialities-changed'], 'adopting');
218
+ for (let i = 0; i < 3; i++) await h.click(`${ROWS} button[data-walk="off"]`);
219
+ await h.click(`${ROWS} button[data-walk="save"]`);
220
+ assert.equal(h.events.length, 2, 'saving the skills');
221
+ await h.click(`${ROWS} button[data-act="abandon"]`);
222
+ assert.equal(h.events.length, 3, 'stopping');
223
+ const quiet = await boot(page, { catalog: [speciality({ mine: true })] });
224
+ await quiet.click(`${ROWS} button[data-act="train"]`);
225
+ assert.deepEqual(quiet.events, [], 'opening a tool that changes no session says nothing');
226
+ });
227
+
228
+ await test(`${page}: a refused adopt says why and changes nothing`, async () => {
229
+ const h = await boot(page, { answer: (m, p) => (m === 'POST' && /\/adopt$/.test(p) ? { status: 409, data: { message: 'already_adopted' } } : null) });
230
+ await h.click(`${ROWS} button[data-act="adopt"]`);
231
+ assert.equal(h.el('specialities-status').textContent, 'already_adopted');
232
+ assert.ok(!/skill-walk/.test(h.html('specialities-rows')), 'no walkthrough for an adopt that did not happen');
233
+ assert.deepEqual(h.events, [], 'and nothing told the page it changed');
234
+ });
235
+ }
217
236
 
218
237
  summary();