|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * #17556 — the boot banner prints the first-run credentials the APPLICATION |
| 5 | + * contributes (`devLogins` / `devHint`), beneath the one the platform seeded. |
| 6 | + * |
| 7 | + * ## The half `packages/cli` could not write for itself |
| 8 | + * |
| 9 | + * #17081 closed the platform's own half: the `🔑 Dev admin` line now says what |
| 10 | + * that account will and will not see. What it could not do is name an account |
| 11 | + * that DOES see something, because the platform does not know an application's |
| 12 | + * audiences — measured downstream, four of five personas rendered their group |
| 13 | + * and the one the banner printed rendered none. `@objectstack/spec` now |
| 14 | + * declares the channel; this file pins what the banner does with it. |
| 15 | + * |
| 16 | + * ## Four properties, and why each is a pin rather than a preference |
| 17 | + * |
| 18 | + * 1. **ADDITIVE.** The seeded-admin block still renders, unchanged, above. |
| 19 | + * An application-controlled key able to suppress a platform disclosure |
| 20 | + * would let an app hide a live credential the operator was just handed. |
| 21 | + * 2. **DEV ONLY.** A non-development boot renders byte-identically to one |
| 22 | + * declaring nothing — ADR-0115's attention budget is untouched on the path |
| 23 | + * that paragraph was written about. |
| 24 | + * 3. **SCRUBBED.** These strings are author-controlled and reach a TTY, where |
| 25 | + * control bytes are instructions: an escape sequence could erase the rows |
| 26 | + * above or repaint a forged `🔑 Dev admin` row, making the platform's own |
| 27 | + * banner lie on the application's behalf. Every C0/C1 byte becomes U+FFFD, |
| 28 | + * so an entry occupies exactly the rows it was given. |
| 29 | + * 4. **DECLARING IS NOT SEEDING.** The wording says the application declared |
| 30 | + * these, because that is all a declaration does — nothing creates an |
| 31 | + * account. An entry naming an unseeded account must read as the app's |
| 32 | + * claim, not as a platform credential that broke. |
| 33 | + * |
| 34 | + * The exact sentences are pinned for the same reason #17081's are: the |
| 35 | + * deliverable here is words on a terminal, so the wording is the only thing |
| 36 | + * that can regress. |
| 37 | + */ |
| 38 | + |
| 39 | +import { describe, expect, it, vi } from 'vitest'; |
| 40 | +import { printServerReady, type ServerReadyOptions } from './format.js'; |
| 41 | + |
| 42 | +/** Strip SGR so assertions hold whether or not chalk colours this run. */ |
| 43 | +const SGR = new RegExp(String.fromCharCode(27) + '\\[[0-9;]*m', 'g'); |
| 44 | + |
| 45 | +function render(opts: Partial<ServerReadyOptions>): string[] { |
| 46 | + const lines: string[] = []; |
| 47 | + const spy = vi.spyOn(console, 'error').mockImplementation((...args: unknown[]) => { |
| 48 | + lines.push(args.join(' ').replace(SGR, '')); |
| 49 | + }); |
| 50 | + try { |
| 51 | + printServerReady({ |
| 52 | + externalBaseOrigin: 'http://localhost:4721', |
| 53 | + uiEnabled: true, |
| 54 | + consolePath: '/_console', |
| 55 | + isDev: true, |
| 56 | + pluginCount: 12, |
| 57 | + ...opts, |
| 58 | + } as ServerReadyOptions); |
| 59 | + } finally { |
| 60 | + spy.mockRestore(); |
| 61 | + } |
| 62 | + return lines; |
| 63 | +} |
| 64 | + |
| 65 | +const SEEDED = { email: 'admin@objectos.ai', password: 'admin123' }; |
| 66 | + |
| 67 | +const LOGINS = [ |
| 68 | + { label: 'Hiring admin', email: 'admin@quillstone.example', password: 'demo1234' }, |
| 69 | + { label: 'Job seeker', email: 'candidate01@mail.example', password: 'demo1234' }, |
| 70 | +]; |
| 71 | + |
| 72 | +/** The application block, verbatim, as a real render emits it under NO_COLOR. */ |
| 73 | +const APP_LOGIN_BLOCK = [ |
| 74 | + '', |
| 75 | + ' 👥 App logins: 2 declared by this app', |
| 76 | + ' Hiring admin — admin@quillstone.example / demo1234', |
| 77 | + ' Job seeker — candidate01@mail.example / demo1234', |
| 78 | + ' declared in this app\'s `devLogins` · dev only — the platform seeded none of them', |
| 79 | +]; |
| 80 | + |
| 81 | +const blockOf = (lines: string[]): string[] => { |
| 82 | + const start = lines.findIndex((l) => l.includes('App logins:')); |
| 83 | + return start < 0 ? [] : lines.slice(start - 1, start - 1 + APP_LOGIN_BLOCK.length); |
| 84 | +}; |
| 85 | + |
| 86 | +// ─── 1. What an operator sees ─────────────────────────────────────── |
| 87 | + |
| 88 | +describe('#17556 — the application\'s own credentials reach the banner', () => { |
| 89 | + it('renders the block verbatim, one row per declared account', () => { |
| 90 | + expect(blockOf(render({ seededAdmin: SEEDED, devLogins: LOGINS }))).toEqual(APP_LOGIN_BLOCK); |
| 91 | + }); |
| 92 | + |
| 93 | + it('prints the address alone when the entry declares no password', () => { |
| 94 | + const lines = render({ devLogins: [{ label: 'SSO admin', email: 'sso@quillstone.example' }] }); |
| 95 | + expect(lines).toContain(' SSO admin — sso@quillstone.example'); |
| 96 | + // …and does not invent one: no separator where a password would sit. |
| 97 | + expect(lines.some((l) => l.includes('sso@quillstone.example /'))).toBe(false); |
| 98 | + }); |
| 99 | + |
| 100 | + it('prints an unlabelled entry as the credential alone', () => { |
| 101 | + expect(render({ devLogins: [{ email: 'a@b.example', password: 'x' }] })) |
| 102 | + .toContain(' a@b.example / x'); |
| 103 | + }); |
| 104 | + |
| 105 | + it('renders `devHint` as its own row', () => { |
| 106 | + const lines = render({ devHint: 'run `pnpm seed:demo` first, then sign in as the Hiring admin' }); |
| 107 | + expect(lines).toContain(' 💡 App hint: run `pnpm seed:demo` first, then sign in as the Hiring admin'); |
| 108 | + }); |
| 109 | +}); |
| 110 | + |
| 111 | +// ─── 2. ADDITIVE — the platform's disclosure survives ─────────────── |
| 112 | + |
| 113 | +describe('#17556 — additive: the seeded-admin block is untouched and comes first', () => { |
| 114 | + it('leaves the #17081 credential block byte-identical', () => { |
| 115 | + const withApp = render({ seededAdmin: SEEDED, devLogins: LOGINS, devHint: 'seed first' }); |
| 116 | + const withoutApp = render({ seededAdmin: SEEDED }); |
| 117 | + |
| 118 | + const devAdminBlock = (lines: string[]) => { |
| 119 | + const start = lines.findIndex((l) => l.includes('Dev admin:')); |
| 120 | + return lines.slice(start - 1, start + 4); |
| 121 | + }; |
| 122 | + expect(devAdminBlock(withApp)).toEqual(devAdminBlock(withoutApp)); |
| 123 | + // Positive control: that slice is five real lines, not two empties agreeing. |
| 124 | + expect(devAdminBlock(withoutApp)).toHaveLength(5); |
| 125 | + expect(devAdminBlock(withoutApp)[1]).toContain('admin@objectos.ai'); |
| 126 | + }); |
| 127 | + |
| 128 | + it('renders beneath it, never instead of it', () => { |
| 129 | + const lines = render({ seededAdmin: SEEDED, devLogins: LOGINS }); |
| 130 | + expect(lines.findIndex((l) => l.includes('Dev admin:'))).toBeGreaterThan(-1); |
| 131 | + expect(lines.findIndex((l) => l.includes('App logins:'))) |
| 132 | + .toBeGreaterThan(lines.findIndex((l) => l.includes('Dev admin:'))); |
| 133 | + }); |
| 134 | + |
| 135 | + it('still prints when the platform seeded nothing — an app that seeds its own accounts', () => { |
| 136 | + const lines = render({ devLogins: LOGINS }); |
| 137 | + expect(lines.some((l) => l.includes('Dev admin:'))).toBe(false); |
| 138 | + expect(blockOf(lines)).toEqual(APP_LOGIN_BLOCK); |
| 139 | + }); |
| 140 | +}); |
| 141 | + |
| 142 | +// ─── 3. DEV ONLY, and silent when nothing is declared ─────────────── |
| 143 | + |
| 144 | +describe('#17556 — the block is gated, and absent by default', () => { |
| 145 | + it('prints nothing on a non-development boot, for either key', () => { |
| 146 | + const lines = render({ isDev: false, seededAdmin: SEEDED, devLogins: LOGINS, devHint: 'seed first' }); |
| 147 | + expect(lines.some((l) => l.includes('App logins:'))).toBe(false); |
| 148 | + expect(lines.some((l) => l.includes('App hint:'))).toBe(false); |
| 149 | + expect(lines.some((l) => l.includes('quillstone'))).toBe(false); |
| 150 | + }); |
| 151 | + |
| 152 | + it('is byte-identical to a boot declaring nothing when both keys are absent, empty or blank', () => { |
| 153 | + const baseline = render({ seededAdmin: SEEDED }); |
| 154 | + for (const declared of [{}, { devLogins: [] }, { devHint: '' }, { devHint: ' ' }, { devLogins: [], devHint: '' }]) { |
| 155 | + expect(render({ seededAdmin: SEEDED, ...declared })).toEqual(baseline); |
| 156 | + } |
| 157 | + // Positive control: the same comparison DOES move when something is declared. |
| 158 | + expect(render({ seededAdmin: SEEDED, devLogins: LOGINS })).not.toEqual(baseline); |
| 159 | + }); |
| 160 | + |
| 161 | + it('skips an entry with no usable address rather than printing a blank credential', () => { |
| 162 | + const lines = render({ devLogins: [{ email: '' }, { email: 'real@b.example' }] as ServerReadyOptions['devLogins'] }); |
| 163 | + expect(lines).toContain(' 👥 App logins: 1 declared by this app'); |
| 164 | + expect(lines).toContain(' real@b.example'); |
| 165 | + }); |
| 166 | +}); |
| 167 | + |
| 168 | +// ─── 4. SCRUBBED — author text cannot repaint the banner ──────────── |
| 169 | + |
| 170 | +describe('#17556 — control bytes in author-controlled text are neutralised', () => { |
| 171 | + const ESC = String.fromCharCode(27); |
| 172 | + |
| 173 | + it('a hint carrying an escape sequence occupies exactly one row, with the bytes replaced', () => { |
| 174 | + const hostile = `${ESC}[2J${ESC}[H🔑 Dev admin: attacker@evil.example / hunter2`; |
| 175 | + const lines = render({ seededAdmin: SEEDED, devHint: hostile }); |
| 176 | + |
| 177 | + const hintRows = lines.filter((l) => l.includes('App hint:')); |
| 178 | + expect(hintRows).toHaveLength(1); |
| 179 | + expect(hintRows[0]).not.toContain(ESC); |
| 180 | + expect(hintRows[0]).toContain('�'); |
| 181 | + // The visible characters are passed through — this is neutralisation, not |
| 182 | + // redaction, so an author who wrote one can see what they wrote. |
| 183 | + expect(hintRows[0]).toContain('attacker@evil.example'); |
| 184 | + // …and exactly one `🔑 Dev admin:` row exists: the forged one is inside the |
| 185 | + // hint row, not a row of its own. |
| 186 | + expect(lines.filter((l) => l.startsWith(' 🔑 Dev admin: '))).toHaveLength(1); |
| 187 | + }); |
| 188 | + |
| 189 | + it('a newline in a credential cannot open a row of its own', () => { |
| 190 | + const lines = render({ devLogins: [{ label: 'x\ny', email: 'a@b.example', password: 'p\rq' }] }); |
| 191 | + const rows = lines.filter((l) => l.includes('a@b.example')); |
| 192 | + expect(rows).toHaveLength(1); |
| 193 | + expect(rows[0]).toBe(' x�y — a@b.example / p�q'); |
| 194 | + }); |
| 195 | + |
| 196 | + it('control-byte-free text is passed through unchanged', () => { |
| 197 | + // The dark control for the two assertions above: the scrubber must be |
| 198 | + // invisible on ordinary input, or "it was replaced" says nothing. |
| 199 | + const lines = render({ devLogins: [{ label: 'Hiring admin', email: 'admin@quillstone.example', password: 'demo1234' }] }); |
| 200 | + expect(lines).toContain(' Hiring admin — admin@quillstone.example / demo1234'); |
| 201 | + expect(lines.some((l) => l.includes('�'))).toBe(false); |
| 202 | + }); |
| 203 | +}); |
0 commit comments