@bongos/core 1.21.45 → 1.21.46

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.
@@ -0,0 +1,63 @@
1
+ 'use strict';
2
+
3
+ // modules/provisioning/manifest-truth.js — what the wizard is told about the GitHub
4
+ // sign-in leg (the GitHub-App-Manifest handshake, ADR 0133), at every stage.
5
+ //
6
+ // WHY (task 1004572, live on 2026-10-04). A founder setting up a project saw
7
+ // "Waiting for your approval on GitHub…" while the platform was already placing
8
+ // credentials, then "GitHub setup didn't start. Nothing was changed on GitHub" after
9
+ // GitHub HAD created an app on their account, and — once a setup link lapsed — no
10
+ // button at all, forever, because nothing ever flips a lapsed 'pending' row.
11
+ // These helpers make the read surface say what is actually true. PURE: no DB, no
12
+ // network; split out because provisioning.js sits at the 1500-line ratchet.
13
+
14
+ // The status a manifest row MEANS right now. Only 'pending' decays: past expires_at
15
+ // the callback refuses its code (attachManifestCode's TTL guard in SQL), so a lapsed
16
+ // 'pending' row is expired in every sense but the column.
17
+ function effectiveManifestStatus(row, now = Date.now()) {
18
+ const status = String((row && row.status) || '');
19
+ if (status === 'pending' && row.expires_at && new Date(row.expires_at).getTime() <= now) return 'expired';
20
+ return status;
21
+ }
22
+
23
+ // How far a FAILED attempt got, as a closed vocabulary the wizard turns into a
24
+ // sentence. The raw last_error never leaves the server (the status route is public
25
+ // by state token). Read from the row's shape, never from error-message text:
26
+ // 'not_approved' — the runner never picked it up (attempts 0): nothing we
27
+ // know of happened on GitHub's side.
28
+ // 'sign_in_unconfirmed' — GitHub handed over the credentials (the App's slug is
29
+ // recorded) and they were placed, but the project never
30
+ // confirmed sign-in works. An App exists on the founder's
31
+ // account, so "try again" makes a second one.
32
+ // 'finish_failed' — GitHub approved, but turning that into credentials on
33
+ // the project failed before the App was recorded.
34
+ const MANIFEST_FAILURES = Object.freeze(['not_approved', 'sign_in_unconfirmed', 'finish_failed']);
35
+
36
+ function manifestFailure(row) {
37
+ if (!row || !(Number(row.attempts) > 0)) return 'not_approved';
38
+ if (row.app_slug) return 'sign_in_unconfirmed';
39
+ return 'finish_failed';
40
+ }
41
+
42
+ // The GitHub-App manifest leg's truth for an instance, as the instance read carries
43
+ // it (task 1003235): the latest attempt's lifecycle status + the App's public slug,
44
+ // in the same vocabulary as GET /github-app/status ('pending' | 'code_received' |
45
+ // 'converting' | 'done' | 'error' | 'expired'), so the wizard can seed `live.manifest`
46
+ // after a reload, a second tab, or another device. null = no attempt ever made.
47
+ // status — the EFFECTIVE status (above).
48
+ // failure — on 'error' only, how far it got (above); null otherwise.
49
+ // started_at — when the setup link was minted, so a reloaded page can still offer
50
+ // "start again" once the wait has clearly gone wrong.
51
+ // An allow-list projection of the row, never the row itself (it holds GitHub's code).
52
+ function publicGithubApp(manifestRow, now = Date.now()) {
53
+ if (!manifestRow || !manifestRow.status) return null;
54
+ const status = effectiveManifestStatus(manifestRow, now);
55
+ return {
56
+ status,
57
+ app_slug: manifestRow.app_slug || null,
58
+ failure: status === 'error' ? manifestFailure(manifestRow) : null,
59
+ started_at: manifestRow.created_at ? new Date(manifestRow.created_at).toISOString() : null,
60
+ };
61
+ }
62
+
63
+ module.exports = { effectiveManifestStatus, manifestFailure, publicGithubApp, MANIFEST_FAILURES };
@@ -477,17 +477,9 @@ function publicInstance(row) {
477
477
  };
478
478
  }
479
479
 
480
- // The GitHub-App manifest leg's truth for an instance, as the read surface carries
481
- // it (task 1003235): the latest attempt's lifecycle status + the App's public slug.
482
- // Same vocabulary as GET /github-app/status ('pending' | 'code_received' |
483
- // 'converting' | 'done' | 'error' | 'expired'), so the wizard can seed its
484
- // `live.manifest` from a plain instance read after a reload, a second tab, or
485
- // another device — no sessionStorage bridge needed. null = no attempt ever made.
486
- // PURE: an allow-list projection of the manifest row, never the row itself.
487
- function publicGithubApp(manifestRow) {
488
- if (!manifestRow || !manifestRow.status) return null;
489
- return { status: String(manifestRow.status), app_slug: manifestRow.app_slug || null };
490
- }
480
+ // The GitHub-App manifest leg's truth as the read surface carries it (task 1003235;
481
+ // task 1004572 made it tell the truth at every stage) — moved to manifest-truth.js.
482
+ const { publicGithubApp } = require('./manifest-truth');
491
483
 
492
484
  // The env variables that carry this instance's settings, as the instance reads
493
485
  // them: { <PREFIX>_PLATFORM_VISIBILITY, <PREFIX>_JOINABILITY } (task 1003139 /
@@ -1405,10 +1405,12 @@ module.exports = function provisioningRoutes() {
1405
1405
  const row = await provisioning.getOAuthManifestByState(pool, state);
1406
1406
  if (!row) return res.status(404).json({ ok: false, error: 'unknown_state' });
1407
1407
  const inst = await provisioning.getInstanceById(pool, row.instance_id).catch(() => null);
1408
- const status = row.status;
1408
+ // EFFECTIVE status + how far a failure got (task 1004572, manifest-truth.js)
1409
+ const { status, failure } = provisioning.publicGithubApp(row);
1409
1410
  return res.json({
1410
1411
  ok: true,
1411
1412
  status,
1413
+ failure,
1412
1414
  ready: status === 'done',
1413
1415
  terminal: status === 'done' || status === 'error' || status === 'expired',
1414
1416
  domain: inst && inst.domain ? inst.domain : null,
@@ -6533,7 +6533,7 @@ summary{min-height:24px;padding:3px 0;}
6533
6533
  return '<a href="' + (instanceId ? '?view=manage&id=' + encodeURIComponent(instanceId) : '?view=mine') +
6534
6534
  '">' + label + '</a>';
6535
6535
  }
6536
- var live = { instStatus: null, addrReady: false, manifest: null, manifestMsg: '', manifestCode: '', appSlug: null };
6536
+ var live = { instStatus: null, addrReady: false, manifest: null, manifestMsg: '', manifestCode: '', manifestFailure: null, appSlug: null };
6537
6537
  var planPromises = {}; /* mode|domain → Promise<steps[]> */
6538
6538
  var lastStepsHtml = '';
6539
6539
  var lastProgHtml = ''; /* same change-only contract, for the progress strip */
@@ -6654,14 +6654,24 @@ summary{min-height:24px;padding:3px 0;}
6654
6654
  details (task 1003244). The one refusal a founder can act on — no
6655
6655
  address yet — says where to go instead of what the server said. */
6656
6656
  var snag, raw = '';
6657
+ /* a failure AFTER GitHub's approval left an app on the founder's account,
6658
+ so "nothing was changed" would be false — the server says how far it got
6659
+ (live.manifestFailure, task 1004572) and the words follow it */
6657
6660
  if (live.manifest === 'expired') snag = 'That setup link expired (they last 30 minutes) — mint a fresh one.';
6658
6661
  else if (live.manifestCode === 'domain_required') snag = 'This project needs an address first — attach one from ' + projectPageLink('its own page') + ', then come back to this step.';
6662
+ else if (live.manifestFailure === 'sign_in_unconfirmed') {
6663
+ var appLink = live.appSlug ? '<a href="https://github.com/settings/apps/' + esc(live.appSlug) + '" target="_blank" rel="noopener">your app on GitHub</a>' : 'the app on your GitHub account';
6664
+ return '<li data-onboard-step="oauth-app"><b>Wire GitHub sign-in</b><p>GitHub approved the app and the platform placed its credentials on your project, but your project didn’t confirm that sign-in works. Trying again would make a second app on your GitHub account and is unlikely to fix this — it needs a look from the platform team. <a href="/contact">Contact us</a> and mention ' + appLink + '.</p>' +
6665
+ progressMarkup(1, 1, 'Stopped: your project didn’t confirm sign-in.', 'isErr', 'signin') +
6666
+ '<button type="button" class="linklike" data-action="manifest-start">Try again anyway</button></li>';
6667
+ }
6668
+ else if (live.manifestFailure === 'finish_failed') snag = 'GitHub approved the app, but the platform couldn’t finish setting up sign-in on your project. The app GitHub made is still on your account — delete it first (GitHub → Settings → Developer settings → GitHub Apps) so you don’t end up with two, then try again.';
6659
6669
  else { snag = 'GitHub setup didn’t start. Nothing was changed on GitHub — try again.'; raw = live.manifestMsg; }
6660
6670
  return '<li data-onboard-step="oauth-app"><b>Wire GitHub sign-in</b><p>' + snag + '</p>' +
6661
6671
  (raw ? '<details><summary>Technical details</summary><p>' + esc(raw) + '</p></details>' : '') +
6662
6672
  '<button type="button" class="ghbtn" data-action="manifest-start">' + GH_ICON + 'Set up GitHub sign-in</button>' + manualOauthDetails() + '</li>';
6663
6673
  }
6664
- if (live.manifest === 'code_received') {
6674
+ if (live.manifest === 'code_received' || live.manifest === 'converting') {
6665
6675
  /* GitHub's half is done — say so, rather than keep telling the founder
6666
6676
  to approve an app they just approved */
6667
6677
  autoOpenArmed = true;
@@ -6670,7 +6680,7 @@ summary{min-height:24px;padding:3px 0;}
6670
6680
  }
6671
6681
  if (live.manifest) { /* pending — GitHub holds the manifest, nobody has approved it yet */
6672
6682
  autoOpenArmed = true;
6673
- return '<li data-onboard-step="oauth-app"><b>Wire GitHub sign-in</b><p>Waiting on GitHub — approve the app in the tab that opened. Once approved, the platform places the credentials and verifies sign-in on its own; this step ticks itself.</p>' +
6683
+ return '<li data-onboard-step="oauth-app"><b>Wire GitHub sign-in</b><p>Waiting on GitHub — approve the app in the tab that opened. No GitHub tab? It may have opened behind this window or in another one. Once approved, the platform places the credentials and verifies sign-in on its own; this step ticks itself.</p>' +
6674
6684
  progressMarkup(0, 0, 'Waiting for your approval on GitHub…', '', 'signin') + autoOpenTick() +
6675
6685
  (manifestStale ? '<button type="button" class="linklike" data-action="manifest-start">Didn’t get to GitHub? Start the setup again</button>' : '') + '</li>';
6676
6686
  }
@@ -6889,7 +6899,7 @@ summary{min-height:24px;padding:3px 0;}
6889
6899
  inp.type = 'hidden'; inp.name = 'manifest'; inp.value = JSON.stringify(d.manifest);
6890
6900
  form.appendChild(inp); document.body.appendChild(form);
6891
6901
  form.submit(); form.remove();
6892
- live.manifest = 'pending'; live.manifestMsg = '';
6902
+ live.manifest = 'pending'; live.manifestMsg = ''; live.manifestFailure = null;
6893
6903
  manifestStartedAt = Date.now(); manifestStale = false;
6894
6904
  rememberManifest(d.state, 'pending');
6895
6905
  renderSteps();
@@ -6897,12 +6907,21 @@ summary{min-height:24px;padding:3px 0;}
6897
6907
  }).catch(function (err) {
6898
6908
  if (String(err && err.message) === 'signing in') return;
6899
6909
  if (tab) { try { tab.close(); } catch (e) {} }
6900
- live.manifest = 'error'; live.manifestMsg = String((err && err.message) || 'could not start');
6910
+ live.manifest = 'error'; live.manifestFailure = null; live.manifestMsg = String((err && err.message) || 'could not start');
6901
6911
  live.manifestCode = String((err && err.code) || '');
6902
6912
  renderSteps();
6903
6913
  });
6904
6914
  }
6905
6915
 
6916
+ /* the "start again" offer once a wait has clearly gone wrong — measured from
6917
+ when the link was MINTED (the server's started_at after a reload), so a
6918
+ reloaded page offers it too instead of never (task 1004572) */
6919
+ function manifestInFlight() {
6920
+ return live.manifest === 'pending' || live.manifest === 'code_received' || live.manifest === 'converting';
6921
+ }
6922
+ function noteManifestWait() {
6923
+ if (live.manifest === 'pending' && !manifestStale && manifestStartedAt && (Date.now() - manifestStartedAt) > 90000) { manifestStale = true; renderSteps(); }
6924
+ }
6906
6925
  function pollManifest(stateToken) {
6907
6926
  stopManifestPoll();
6908
6927
  manifestState = stateToken;
@@ -6916,8 +6935,9 @@ summary{min-height:24px;padding:3px 0;}
6916
6935
  if (myGen !== manifestGen) return;
6917
6936
  if (d.app_slug && d.app_slug !== live.appSlug) { live.appSlug = d.app_slug; rememberManifest(undefined, undefined, d.app_slug); renderSteps(); }
6918
6937
  var next = d.ready ? 'done' : (d.status || 'pending');
6919
- if (next !== live.manifest) { live.manifest = next; rememberManifest(undefined, next); renderSteps(); }
6920
- else if (next === 'pending' && !manifestStale && manifestStartedAt && (Date.now() - manifestStartedAt) > 90000) { manifestStale = true; renderSteps(); }
6938
+ var failure = d.failure || null;
6939
+ if (next !== live.manifest || failure !== live.manifestFailure) { live.manifest = next; live.manifestFailure = failure; rememberManifest(undefined, next); renderSteps(); }
6940
+ else noteManifestWait();
6921
6941
  if (!d.terminal) manifestPollTimer = setTimeout(tick, 4000);
6922
6942
  else manifestPollTimer = null; /* a stale fired id would read as "still polling" and resume a finished poll */
6923
6943
  })
@@ -7119,10 +7139,15 @@ summary{min-height:24px;padding:3px 0;}
7119
7139
  var ga = data.github_app;
7120
7140
  if (ga && ga.status && !manifestPollTimer) {
7121
7141
  var seeded = ga.status === 'done' ? 'done' : ga.status;
7122
- var seedChanged = seeded !== live.manifest || (!!ga.app_slug && ga.app_slug !== live.appSlug);
7142
+ var seedFailure = ga.failure || null;
7143
+ var seedChanged = seeded !== live.manifest || seedFailure !== live.manifestFailure || (!!ga.app_slug && ga.app_slug !== live.appSlug);
7123
7144
  if (ga.app_slug) live.appSlug = ga.app_slug;
7124
- live.manifest = seeded;
7145
+ live.manifest = seeded; live.manifestFailure = seedFailure;
7146
+ /* the wait is timed from when the link was MINTED, so a reload still
7147
+ reaches the "start again" offer (task 1004572) */
7148
+ if (!manifestStartedAt && ga.started_at) manifestStartedAt = Date.parse(ga.started_at) || 0;
7125
7149
  if (seedChanged) { rememberManifest(undefined, live.manifest, live.appSlug || undefined); renderSteps(); }
7150
+ else noteManifestWait();
7126
7151
  }
7127
7152
  /* the checklist reflects live state (task 1002694): a status transition —
7128
7153
  e.g. the scaffold landing — re-renders the steps (change-only, so the
@@ -7131,7 +7156,9 @@ summary{min-height:24px;padding:3px 0;}
7131
7156
  live.instStatus = inst.status; live.addrReady = addressReady(inst); renderSteps();
7132
7157
  }
7133
7158
  var terminal = renderProgress(inst);
7134
- if (!terminal) pollTimer = setTimeout(tick, 5000);
7159
+ /* a GitHub leg still in flight keeps this read alive even once the
7160
+ project is up — after a reload it is the ONLY thing watching it */
7161
+ if (!terminal || manifestInFlight()) pollTimer = setTimeout(tick, 5000);
7135
7162
  else stopPolling();
7136
7163
  })
7137
7164
  .catch(function (err) {
@@ -7160,7 +7187,7 @@ summary{min-height:24px;padding:3px 0;}
7160
7187
  instanceId = null;
7161
7188
  watchPending = false; manifestPending = false; manifestState = null;
7162
7189
  manifestStartedAt = 0; manifestStale = false;
7163
- live = { instStatus: null, addrReady: false, manifest: null, manifestMsg: '', manifestCode: '', appSlug: null };
7190
+ live = { instStatus: null, addrReady: false, manifest: null, manifestMsg: '', manifestCode: '', manifestFailure: null, appSlug: null };
7164
7191
  lastStepsHtml = '';
7165
7192
  lastProgHtml = '';
7166
7193
  try { sessionStorage.removeItem(DRAFT_KEY); } catch (e) {}
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@bongos/core",
3
- "version": "1.21.45",
3
+ "version": "1.21.46",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@bongos/core",
9
- "version": "1.21.45",
9
+ "version": "1.21.46",
10
10
  "license": "AGPL-3.0-or-later",
11
11
  "dependencies": {
12
12
  "express": "^4.21.2",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bongos/core",
3
- "version": "1.21.45",
3
+ "version": "1.21.46",
4
4
  "description": "Cloud Bongos — the AI-first build platform core (GDS + platform surfaces + module system), installed as a versioned dependency (ADR 0108).",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "main": "src/platform-server.js",
@@ -9034,5 +9034,11 @@
9034
9034
  "id": "1004497",
9035
9035
  "text": "Artists can now edit any hall page's words right where they stand. In Artistry mode, \"Edit words\" offers to take the page; the words get an underline and can be typed over, a review lists each change as was/now, and \"Send for"
9036
9036
  }
9037
+ ],
9038
+ "1.21.46": [
9039
+ {
9040
+ "id": "1004572",
9041
+ "text": "Setting up GitHub sign-in for a new project now says what is really happening at each step, and always leaves a way forward if it gets stuck."
9042
+ }
9037
9043
  ]
9038
9044
  }
@@ -1095,7 +1095,9 @@ async function placeManifestCreds(inst, mrow, deps) {
1095
1095
  await sleep(MANIFEST_VERIFY_INTERVAL_MS);
1096
1096
  }
1097
1097
  if (!authConfigured) {
1098
- return { ok: false, codeSpent: true, error: 'the credentials are placed, but the project did not report sign-in ready in time' };
1098
+ // The App now EXISTS on the owner's account — keep its id + slug on the row so
1099
+ // the wizard can name it and say why "try again" makes a second one (task 1004572).
1100
+ return { ok: false, codeSpent: true, appId: creds.appId, appSlug: creds.appSlug, error: 'the credentials are placed, but the project did not report sign-in ready in time' };
1099
1101
  }
1100
1102
  log(' [oauth-manifest] ✓ /healthz auth_configured=true — sign-in is live');
1101
1103
  } else {
@@ -1147,7 +1149,7 @@ async function drainOAuthManifests(deps) {
1147
1149
  // single-use, so resetting the row to 'code_received' guarantees the
1148
1150
  // next tick re-converts a burned code and 404s forever. Only failures
1149
1151
  // that happened BEFORE the conversion stay retryable.
1150
- if (result.codeSpent) await provisioning.resolveOAuthManifest(db, mrow.id, 'error', { last_error: result.error, github_code: null });
1152
+ if (result.codeSpent) await provisioning.resolveOAuthManifest(db, mrow.id, 'error', { last_error: result.error, github_code: null, ...(result.appSlug ? { app_id: result.appId, app_slug: result.appSlug } : {}) });
1151
1153
  else if (mrow.attempts >= MAX_INTENT_ATTEMPTS) await provisioning.resolveOAuthManifest(db, mrow.id, 'error', { last_error: result.error });
1152
1154
  else await provisioning.resolveOAuthManifest(db, mrow.id, 'code_received', { last_error: result.error });
1153
1155
  errors++; log(` ✖ oauth-manifest #${mrow.id}: ${result.error}`);
@@ -127,6 +127,19 @@ function renderAuthErrorPage(heading, detail, opts = {}) {
127
127
  </body></html>`;
128
128
  }
129
129
 
130
+ // The project has no way to sign anyone in yet: neither its own GitHub app nor
131
+ // sign-in through the platform (task 1004572). It used to answer a bare 503
132
+ // "auth not configured", which told a founder mid-setup nothing they could act on.
133
+ // Still a 503 — the service genuinely is not available — but in words, and
134
+ // pointing the one person who can fix it at the step that does.
135
+ const AUTH_NOT_CONFIGURED_DETAIL = "Sign-in isn't set up on this project yet. If it's your project, go back to its setup checklist on the platform where you created it and finish the \"Wire GitHub sign-in\" step. Otherwise, ask the project's owner.";
136
+ function sendAuthNotConfigured(res) {
137
+ return res.status(503).type('text/html').send(renderAuthErrorPage(
138
+ "Sign-in isn't set up yet", AUTH_NOT_CONFIGURED_DETAIL,
139
+ { subtitle: "This project can't sign anyone in yet.", cta: { href: '/', label: 'Back to the project' }, note: 'Nothing is wrong with your account.' },
140
+ ));
141
+ }
142
+
130
143
  // renderAccessPendingPage — the calm "hang tight" page shown instead of the red
131
144
  // dead-end when admission is plausibly imminent (task 1002097): the configured
132
145
  // firstAdmin during the bootstrap window, or a login with a pending request.
@@ -681,7 +694,7 @@ module.exports = function buildAuthRouter() {
681
694
  // Either direct-GitHub creds OR platform-IdP federation must be configured
682
695
  // (ADR 0141 §1) — a federated instance has no GitHub app of its own.
683
696
  if (!auth.authConfigured() && !auth.idpConfigured()) {
684
- return res.status(503).type('text/plain').send('auth not configured');
697
+ return sendAuthNotConfigured(res);
685
698
  }
686
699
  const wantsRepos = req.query.repos === '1' || req.query.repos === 'true';
687
700
  // A sign-in begun on a satellite hub host (builders./status.) restarts on
@@ -842,7 +855,7 @@ module.exports = function buildAuthRouter() {
842
855
  // rank: public — OAuth callback; the state cookie + code are the bearer.
843
856
  router.get('/auth/web/callback', async (req, res) => {
844
857
  if (!auth.authConfigured() && !auth.idpConfigured()) {
845
- return res.status(503).type('text/plain').send('auth not configured');
858
+ return sendAuthNotConfigured(res);
846
859
  }
847
860
  const expectedState = parseCookie(req, STATE_COOKIE) || parseCookie(req, STATE_COOKIE_LEGACY);
848
861
  const { state, code, error } = req.query;
package/src/module-api.js CHANGED
@@ -75,7 +75,7 @@ const { responsibilityFor, ROLE_RESPONSIBILITIES } = require('./role-responsibil
75
75
  // MAJOR (see allowBoxScope below): passes the request through untouched.
76
76
  function deprecatedNoopMiddleware(_req, _res, next) { next(); }
77
77
 
78
- const CORE_VERSION = '1.21.45'; // CI auto-patch carrier (ADR 0161); changelog: docs/module-api-changelog.md
78
+ const CORE_VERSION = '1.21.46'; // CI auto-patch carrier (ADR 0161); changelog: docs/module-api-changelog.md
79
79
 
80
80
  // A namespaced logger so a module's log lines are attributable + consistent.
81
81
  // Usage: const log = api.logger('discord'); log.info('mounted');
@@ -206,7 +206,8 @@ test('the fallback checklist carries every human step the canonical plan has', (
206
206
 
207
207
  /* ── the manifest leg: acknowledges GitHub, offers a way out, survives a reload ── */
208
208
  test('the manifest step acknowledges code_received, offers a restart after a stall, and rides the CREATED record', () => {
209
- assert.match(SCRIPT, /if \(live\.manifest === 'code_received'\)/, 'GitHub’s half is acknowledged');
209
+ // 'converting' is the same stage — it used to fall through to "waiting for approval" (task 1004572)
210
+ assert.match(SCRIPT, /if \(live\.manifest === 'code_received' \|\| live\.manifest === 'converting'\)/, 'GitHub’s half is acknowledged');
210
211
  assert.match(SCRIPT, /GitHub’s part is done/);
211
212
  assert.match(SCRIPT, /manifestStale \? '<button type="button" class="linklike" data-action="manifest-start">/, 'a stalled wait gets a restart door');
212
213
  assert.match(SCRIPT, /\(Date\.now\(\) - manifestStartedAt\) > 90000/, 'after ~90 seconds');
@@ -558,7 +559,7 @@ test('a manifest error says a plain sentence, folds the route text, and sends a
558
559
  assert.match(steps, /\(raw \? '<details><summary>Technical details<\/summary><p>' \+ esc\(raw\) \+ '<\/p><\/details>' : ''\)/);
559
560
  assert.match(SCRIPT, /e\.code = \(d\.error && d\.error\.code\) \|\| '';/, 'the route code travels with the error');
560
561
  assert.match(SCRIPT, /live\.manifestCode = String\(\(err && err\.code\) \|\| ''\);/);
561
- assert.equal((SCRIPT.match(/manifestMsg: '', manifestCode: '', appSlug: null/g) || []).length, 2, 'both resets carry the code');
562
+ assert.equal((SCRIPT.match(/manifestMsg: '', manifestCode: '', manifestFailure: null, appSlug: null/g) || []).length, 2, 'both resets carry the code (and, since task 1004572, the failure stage)');
562
563
  });
563
564
 
564
565
  test('the progress rail is gone (task 1004504): no painter, no repaint at the done panel, no static rail', () => {
@@ -1723,6 +1723,59 @@ await ta('a SPENT code is never re-converted — terminal error, no code_receive
1723
1723
  assert.ok(!resolves.some((x) => x.status === 'code_received'), 'never reset for a doomed retry');
1724
1724
  });
1725
1725
 
1726
+ // Task 1004572: once the credentials are placed, an App EXISTS on the owner's GitHub
1727
+ // account whether or not the project then confirms sign-in. The failed row must keep
1728
+ // its id + slug, or the wizard can only say "GitHub setup didn't start" — false, and
1729
+ // it sends the founder to make a second App (live on mercury, 2026-10-04).
1730
+ await ta('a sign-in check that never confirms still records WHICH App GitHub made (task 1004572)', async () => {
1731
+ const inst = { ...coTenant, domain: 'mercury.example.com' };
1732
+ const deps = {
1733
+ apply: true, privileged: false, log: () => {}, sleep: async () => {},
1734
+ convertManifestCode: async () => ({ clientId: 'Iv1.abcdef0123456789', clientSecret: 'z'.repeat(40), appId: 5189633, appSlug: 'mercury-cloudbongos-com' }),
1735
+ exec: () => ({ ok: true, stdout: '{"ok":true,"auth_configured":false}' }),
1736
+ writeFile: () => ({ ok: true }),
1737
+ };
1738
+ const r = await P.placeManifestCreds(inst, { github_code: 'C', attempts: 1 }, deps);
1739
+ assert.equal(r.ok, false);
1740
+ assert.equal(r.appId, 5189633, 'the App id rides the failure');
1741
+ assert.equal(r.appSlug, 'mercury-cloudbongos-com', 'the App slug rides the failure');
1742
+
1743
+ const resolves = [];
1744
+ let claims = 0;
1745
+ await P.drainOAuthManifests({
1746
+ ...deps, db: {},
1747
+ provisioning: {
1748
+ claimNextOAuthManifest: async () => (claims++ === 0 ? { id: 18, instance_id: 53, github_code: 'C', attempts: 1 } : null),
1749
+ getInstanceById: async () => inst,
1750
+ resolveOAuthManifest: async (_db, _id, status, patch = {}) => { resolves.push({ status, patch }); },
1751
+ recordEvent: async () => {},
1752
+ },
1753
+ });
1754
+ assert.equal(resolves.length, 1);
1755
+ assert.equal(resolves[0].status, 'error');
1756
+ assert.equal(resolves[0].patch.app_slug, 'mercury-cloudbongos-com', 'the error row names the App');
1757
+ assert.equal(resolves[0].patch.app_id, 5189633);
1758
+ assert.equal(resolves[0].patch.github_code, null, 'the burned code is still scrubbed');
1759
+ });
1760
+
1761
+ await ta('a failure BEFORE GitHub handed over credentials claims no App (task 1004572)', async () => {
1762
+ const resolves = [];
1763
+ let claims = 0;
1764
+ await P.drainOAuthManifests({
1765
+ apply: true, privileged: false, log: () => {}, sleep: async () => {}, db: {},
1766
+ exec: () => ({ ok: true, stdout: '' }), writeFile: () => ({ ok: true }),
1767
+ convertManifestCode: async () => { throw new Error('GitHub manifest conversion failed: code expired'); },
1768
+ provisioning: {
1769
+ claimNextOAuthManifest: async () => (claims++ === 0 ? { id: 19, instance_id: 53, github_code: 'C', attempts: 1 } : null),
1770
+ getInstanceById: async () => ({ ...coTenant, domain: 'mercury.example.com' }),
1771
+ resolveOAuthManifest: async (_db, _id, status, patch = {}) => { resolves.push({ status, patch }); },
1772
+ recordEvent: async () => {},
1773
+ },
1774
+ });
1775
+ assert.ok(resolves.length >= 1);
1776
+ assert.ok(resolves.every((x) => !('app_slug' in x.patch)), 'no App is named when none was handed over');
1777
+ });
1778
+
1726
1779
  await ta('a PRE-conversion failure stays retryable — the narrowing spared the retry path (F23)', async () => {
1727
1780
  let claims = 0; const resolves = [];
1728
1781
  const deps = {
@@ -158,6 +158,29 @@ console.log('\nGET /provisioning/github-app/status (the page poll → auto-open
158
158
  t("status 'done' → ready:true + terminal:true", res.status === 200 && j.ready === true && j.terminal === true, JSON.stringify(j));
159
159
  provisioning.getOAuthManifestByState = prev;
160
160
  }
161
+ {
162
+ // Task 1004572: a setup link nobody finished lapses after 30 minutes, and the
163
+ // callback refuses it from then on — so the poll must say 'expired' (terminal)
164
+ // rather than 'pending' forever, or the page waits on a link that can never land.
165
+ const prev = provisioning.getOAuthManifestByState;
166
+ provisioning.getOAuthManifestByState = async () => ({ id: 17, instance_id: 42, status: 'pending', attempts: 0, expires_at: new Date(Date.now() - 1000).toISOString() });
167
+ const res = await fetch(`${base}/provisioning/github-app/status?state=GOODSTATE`);
168
+ const j = await res.json();
169
+ t('a LAPSED pending link reads expired + terminal (task 1004572)', res.status === 200 && j.status === 'expired' && j.terminal === true && j.ready === false && j.failure === null, JSON.stringify(j));
170
+ provisioning.getOAuthManifestByState = prev;
171
+ }
172
+ {
173
+ // A failure after GitHub handed over credentials: the poll names how far it got,
174
+ // and never the raw last_error (this route is public by state token).
175
+ const prev = provisioning.getOAuthManifestByState;
176
+ provisioning.getOAuthManifestByState = async () => ({ id: 18, instance_id: 42, status: 'error', attempts: 1, app_slug: 'mercury-signin', last_error: 'the credentials are placed, but the project did not report sign-in ready in time', expires_at: new Date(Date.now() - 1000).toISOString() });
177
+ const res = await fetch(`${base}/provisioning/github-app/status?state=GOODSTATE`);
178
+ const raw = await res.text();
179
+ const j = JSON.parse(raw);
180
+ t("a post-approval failure says failure:'sign_in_unconfirmed' (task 1004572)", j.status === 'error' && j.failure === 'sign_in_unconfirmed' && j.terminal === true, raw);
181
+ t('…and never leaks last_error', !/did not report/.test(raw) && !('last_error' in j), raw);
182
+ provisioning.getOAuthManifestByState = prev;
183
+ }
161
184
  {
162
185
  const res = await fetch(`${base}/provisioning/github-app/status?state=NOPE`);
163
186
  t('unknown state → 404 (no oracle)', res.status === 404, `status=${res.status}`);
@@ -115,10 +115,12 @@ await ta('owner reads their own instance', async () => {
115
115
 
116
116
  await ta('the read carries the GitHub-App leg\'s truth — github_app {status, app_slug} from the latest manifest attempt (task 1003235)', async () => {
117
117
  reset();
118
- manifest = { id: 3, instance_id: 18, status: 'done', app_slug: 'spike-bongos', github_code: 'never-surfaced', state: 'never-surfaced' };
118
+ manifest = { id: 3, instance_id: 18, status: 'done', app_slug: 'spike-bongos', github_code: 'never-surfaced', state: 'never-surfaced', last_error: 'never-surfaced', created_at: '2026-10-04T20:20:56.930Z' };
119
119
  const r = await get('/provisioning/instances/18');
120
120
  assert.equal(r.status, 200, r.raw);
121
- assert.deepEqual(r.body.github_app, { status: 'done', app_slug: 'spike-bongos' }, 'an allow-list projection — the code and the state token never ride the read');
121
+ // task 1004572 added failure + started_at to the allow-list; nothing else rides
122
+ assert.deepEqual(r.body.github_app, { status: 'done', app_slug: 'spike-bongos', failure: null, started_at: '2026-10-04T20:20:56.930Z' }, 'an allow-list projection — the code, the state token and last_error never ride the read');
123
+ assert.doesNotMatch(r.raw, /never-surfaced/);
122
124
  assert.equal(r.body.instance.slug, 'spike', 'the instance projection is untouched');
123
125
  });
124
126
 
@@ -134,8 +136,8 @@ await ta('no manifest attempt yet → github_app is null, not absent (a reload c
134
136
  await ta('publicGithubApp is a pure allow-list projection with the status route\'s vocabulary', async () => {
135
137
  assert.equal(provisioning.publicGithubApp(null), null);
136
138
  assert.equal(provisioning.publicGithubApp({ app_slug: 'x' }), null, 'a row with no status is no truth');
137
- assert.deepEqual(provisioning.publicGithubApp({ status: 'pending', github_code: 'secret' }), { status: 'pending', app_slug: null });
138
- assert.deepEqual(provisioning.publicGithubApp({ status: 'code_received', app_slug: 'mercury-bongos' }), { status: 'code_received', app_slug: 'mercury-bongos' });
139
+ assert.deepEqual(provisioning.publicGithubApp({ status: 'pending', github_code: 'secret' }), { status: 'pending', app_slug: null, failure: null, started_at: null });
140
+ assert.deepEqual(provisioning.publicGithubApp({ status: 'code_received', app_slug: 'mercury-bongos' }), { status: 'code_received', app_slug: 'mercury-bongos', failure: null, started_at: null });
139
141
  });
140
142
 
141
143
  await ta('ANOTHER builder\'s GET → 404 (no existence leak)', async () => {