Skip to content

Commit 2e917a6

Browse files
committed
wip(#30120): Console deployment notice, locales, pins
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cyhB3ePno23ywn1PQd
1 parent ea6179d commit 2e917a6

20 files changed

Lines changed: 1844 additions & 5 deletions

File tree

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* #30120 (ruling A3) — the pieces `os start` decides the image refusal and the
5+
* boot block with. The real boots, refusal and block included, are pinned end
6+
* to end in `test/start-deployment-durability.integration.test.ts`.
7+
*/
8+
9+
import { describe, expect, it } from 'vitest';
10+
import {
11+
DURABILITY_CHECK_ENV,
12+
INTERNAL_DEPLOYMENT_FINDINGS_ENV,
13+
formatDurabilityBootBlock,
14+
formatDurabilityRefusal,
15+
isDefaultedDatabase,
16+
missingDurableVariables,
17+
readDurabilityCheckSignal,
18+
sqliteFileOf,
19+
writeDeploymentFindingsChannel,
20+
} from './start.js';
21+
22+
describe('the image switch', () => {
23+
it.each([
24+
[undefined, 'off'],
25+
['', 'off'],
26+
[' ', 'off'],
27+
['false', 'off'],
28+
['0', 'off'],
29+
['true', 'on'],
30+
['TRUE', 'on'],
31+
[' 1 ', 'on'],
32+
['yes', 'invalid'],
33+
['enabled', 'invalid'],
34+
])('%j reads %s', (raw, verdict) => {
35+
expect(readDurabilityCheckSignal({ [DURABILITY_CHECK_ENV]: raw })).toBe(verdict);
36+
});
37+
38+
it('is not NODE_ENV: os start sets production on every boot, so production alone never refuses', () => {
39+
expect(readDurabilityCheckSignal({ NODE_ENV: 'production' })).toBe('off');
40+
});
41+
});
42+
43+
describe('which variables the image requires and this boot did not get', () => {
44+
it('a database nobody chose is missing; one from the flag, the environment or the project config is not', () => {
45+
expect(isDefaultedDatabase('unified-default')).toBe(true);
46+
expect(isDefaultedDatabase('legacy-file')).toBe(true);
47+
for (const source of ['explicit', 'env', 'config-datasource'] as const) {
48+
expect(isDefaultedDatabase(source)).toBe(false);
49+
}
50+
});
51+
52+
it('names each one missing, in the order the refusal lists them', () => {
53+
expect(missingDurableVariables({ databaseSource: 'unified-default', authSecretSet: false, secretKeySet: false })).toEqual([
54+
'OS_DATABASE_URL',
55+
'OS_AUTH_SECRET',
56+
'OS_SECRET_KEY',
57+
]);
58+
expect(missingDurableVariables({ databaseSource: 'env', authSecretSet: true, secretKeySet: false })).toEqual(['OS_SECRET_KEY']);
59+
expect(missingDurableVariables({ databaseSource: 'env', authSecretSet: true, secretKeySet: true })).toEqual([]);
60+
});
61+
62+
it('reads the file of a file: URL, and nothing of any other', () => {
63+
expect(sqliteFileOf('file:/data/app.db')).toBe('/data/app.db');
64+
expect(sqliteFileOf('file:///data/app.db')).toBe('/data/app.db');
65+
expect(sqliteFileOf('file:')).toBeUndefined();
66+
expect(sqliteFileOf('postgres://u:p@h:5432/db')).toBeUndefined();
67+
});
68+
});
69+
70+
describe('the refusal', () => {
71+
const where = {
72+
authSecretFile: '/home/node/.objectstack/auth-secret',
73+
dataKeyFile: '/home/node/.objectstack/dev-crypto-key',
74+
defaultDatabaseFile: '/home/node/.objectstack/data/objectstack.db',
75+
exists: (f: string) => f.endsWith('auth-secret'),
76+
};
77+
78+
it('names exactly the missing variables, and says how to set each', () => {
79+
const all = formatDurabilityRefusal(['OS_DATABASE_URL', 'OS_AUTH_SECRET', 'OS_SECRET_KEY'], where);
80+
expect(all).toContain('OS_DATABASE_URL, OS_AUTH_SECRET and OS_SECRET_KEY are not set');
81+
expect(all).toMatch(/^ {4}OS_DATABASE_URL {2}your database/m);
82+
expect(all).toContain('file:/path/on/a/mounted/volume/app.db');
83+
expect(all).toMatch(/^ {4}OS_AUTH_SECRET {3}a long random value/m);
84+
expect(all).toMatch(/^ {4}OS_SECRET_KEY {4}32 random bytes/m);
85+
86+
const one = formatDurabilityRefusal(['OS_SECRET_KEY'], where);
87+
expect(one).toContain(': OS_SECRET_KEY is not set');
88+
expect(one).not.toContain('OS_DATABASE_URL');
89+
expect(one).not.toContain('OS_AUTH_SECRET');
90+
});
91+
92+
it('says how a deployment on generated values carries them over, marking what this container holds', () => {
93+
const text = formatDurabilityRefusal(['OS_DATABASE_URL', 'OS_AUTH_SECRET', 'OS_SECRET_KEY'], where);
94+
expect(text).toContain('Carry them over before you set new ones');
95+
expect(text).toContain('docker exec <container> cat <file>');
96+
expect(text).toContain('OS_AUTH_SECRET the contents of /home/node/.objectstack/auth-secret (present in this container)');
97+
expect(text).toContain('OS_SECRET_KEY the contents of /home/node/.objectstack/dev-crypto-key\n');
98+
expect(text).toContain('file:/home/node/.objectstack/data/objectstack.db, if your data is that file on a kept volume');
99+
});
100+
});
101+
102+
describe('the boot block', () => {
103+
it('lists each thing kept on this disk, with its file and the variable that moves it', () => {
104+
const block = formatDurabilityBootBlock({
105+
databaseFile: '/srv/.objectstack/data/objectstack.db',
106+
authSecretFile: '/srv/.objectstack/auth-secret',
107+
dataKeyFile: '/srv/.objectstack/dev-crypto-key',
108+
})!;
109+
expect(block).toContain('Production mode, and this server keeps these on its own disk');
110+
expect(block).toContain('Database: a SQLite file, /srv/.objectstack/data/objectstack.db (OS_DATABASE_URL is not set)');
111+
expect(block).toContain('Sign-in secret: generated and kept in /srv/.objectstack/auth-secret (OS_AUTH_SECRET is not set)');
112+
expect(block).toContain('kept in /srv/.objectstack/dev-crypto-key (OS_SECRET_KEY is not set)');
113+
expect(block).toContain('set OS_DATABASE_URL, OS_AUTH_SECRET and OS_SECRET_KEY');
114+
expect(block).toContain('Administrators see this notice in the Console too.');
115+
});
116+
117+
it('a secret generated for this process only says so', () => {
118+
expect(formatDurabilityBootBlock({ authSecretFile: null })).toContain('generated for this process only');
119+
});
120+
121+
it('a boot that keeps nothing on its disk by default prints nothing', () => {
122+
expect(formatDurabilityBootBlock({})).toBeUndefined();
123+
});
124+
});
125+
126+
describe('the channel to the server process', () => {
127+
// The reader (`service-settings` `deployment-notice.ts`) spells the name in
128+
// its own module: the end-to-end pin reads the findings a real boot hands it.
129+
it('carries the findings as JSON, and is removed when there are none', () => {
130+
const env: Record<string, string | undefined> = { [INTERNAL_DEPLOYMENT_FINDINGS_ENV]: 'stale' };
131+
writeDeploymentFindingsChannel(env, { databaseFile: '/d.db', authSecretFile: null });
132+
expect(JSON.parse(env[INTERNAL_DEPLOYMENT_FINDINGS_ENV]!)).toEqual({ databaseFile: '/d.db', authSecretFile: null });
133+
writeDeploymentFindingsChannel(env, {});
134+
expect(INTERNAL_DEPLOYMENT_FINDINGS_ENV in env).toBe(false);
135+
env[INTERNAL_DEPLOYMENT_FINDINGS_ENV] = 'inherited';
136+
writeDeploymentFindingsChannel(env, undefined);
137+
expect(INTERNAL_DEPLOYMENT_FINDINGS_ENV in env).toBe(false);
138+
});
139+
});

0 commit comments

Comments
 (0)