Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 71 additions & 28 deletions llp/0004-discovered-checkouts.decision.md

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions packages/core/__tests__/settings-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,17 @@ test('native hosting targets accept tailnet names and ports', () => {
for (const platform of ['ios', 'android']) expect(validate({ [platform]: { remote } })).toBe(false);
});

test('maintenance.discoverRoots refuses relative entries, the home folder and the filesystem root', () => {
expect(settingValueError('maintenance.discoverRoots', ['/data/projects', '~/Developer'])).toBeNull();
expect(settingValueError('maintenance.discoverRoots', ['relative/dir'])).toContain('absolute paths');
expect(settingValueError('maintenance.discoverRoots', ['~'])).toContain('too broad');
expect(settingValueError('maintenance.discoverRoots', ['/'])).toContain('too broad');
test('the machine schema accepts a config that still uses maintenance.discoverRoots, without listing it as a setting', () => {
const schema = settingsJsonSchema();
const validate = new Ajv({ strict: false }).compile({ $defs: schema.$defs, $ref: '#/$defs/machine' });
expect(validate({ maintenance: { discoverRoots: ['/old'] } })).toBe(true);
expect(validate({ maintenance: { discoverRoot: ['/old'] } })).toBe(false);
expect(JSON.stringify(schema)).not.toContain('"key":"maintenance.discoverRoots"');
});

test('maintenance.managedFolders refuses relative entries, the home folder and the filesystem root', () => {
expect(settingValueError('maintenance.managedFolders', ['/data/projects', '~/Developer'])).toBeNull();
expect(settingValueError('maintenance.managedFolders', ['relative/dir'])).toContain('absolute paths');
expect(settingValueError('maintenance.managedFolders', ['~'])).toContain('too broad');
expect(settingValueError('maintenance.managedFolders', ['/'])).toContain('too broad');
});
18 changes: 18 additions & 0 deletions packages/core/__tests__/state-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,24 @@ test.each(SETTINGS)('$key resolves its sources and registry default without losi
}
});

test.each([
['only the 2.0.0 name', { discoverRoots: ['/old'] }, ['/old']],
['both names, where the new one wins', { discoverRoots: ['/old'], managedFolders: ['/new'] }, ['/new']],
['the new name cleared to an empty list', { discoverRoots: ['/old'], managedFolders: [] }, []],
])('maintenance.managedFolders reads %s', (_, maintenance, value) => {
expect(machineSettingValue('maintenance.managedFolders', { config: { maintenance }, env: {} })).toEqual({
value,
error: null,
});
});

test('an invalid maintenance.discoverRoots value is reported under that name', () => {
const config = { maintenance: { discoverRoots: ['relative'] } };
expect(machineSettingValue('maintenance.managedFolders', { config, env: {} }).error).toMatch(
/^Invalid maintenance\.discoverRoots value /,
);
});

test.each(['bogus', '-1', '1.5'])('an invalid concurrency environment limit %s refuses before admission', (raw) => {
writeConfig({ concurrency: { maxBuilds: 4 }, projects: {}, repos: {} });
expect(() => getConcurrencyLimits({ env: { STIM_MAX_BUILDS: raw } })).toThrow(
Expand Down
6 changes: 3 additions & 3 deletions packages/core/state/discovery-census.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { discoveryCensusFile } from './paths.ts';
export interface CensusFind {
path: string;
kind: 'reduce-only' | 'dot-folder' | 'untracked' | 'unchecked';
/** The folder whose direct children include the checkout, the one `maintenance.discoverRoots` would take. */
/** The folder whose direct children include the checkout, the one `maintenance.managedFolders` would take. */
folder: string;
/** Whether `maintenance.discoverRoots` can name `folder`: the home folder and the folders holding it cannot. */
/** Whether `maintenance.managedFolders` can name `folder`: the home folder and the folders holding it cannot. */
adoptable: boolean;
/** When its build output was last measured, epoch ms; 0 when it was not measured yet. */
evaluatedAt: number;
Expand Down Expand Up @@ -50,7 +50,7 @@ export interface DiscoveryCensus {
at: number;
/** The `ranAt` of the scan it was derived from. */
scanRanAt: number;
/** The `maintenance.discoverRoots` entries it was classified under, as absolute paths. */
/** The `maintenance.managedFolders` entries it was classified under, as absolute paths. */
roots: string[];
/** The existing, non-broad folders of `roots` with symlinks resolved, as the classification used; commands compare strings only. */
canonicalRoots: string[];
Expand Down
2 changes: 1 addition & 1 deletion packages/core/state/discovery-scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const isTruncation = (value: unknown): value is ScanTruncation =>

/**
* What the last full scan of the home folder found: the checkouts Stim's project detection recognises that
* `maintenance.discoverRoots`, registered projects and the common tool folders do not reach, and what it could not read.
* `maintenance.managedFolders`, registered projects and the common tool folders do not reach, and what it could not read.
*/
export interface DiscoveryScan {
version: 2;
Expand Down
42 changes: 36 additions & 6 deletions packages/core/state/settings-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export function shownSettingType(type: SettingType): Exclude<SettingType, Plugin
* replaces every layer and the default while STIM_HOME is set and `env` is not.
* `ciValue` replaces every layer and the default while CI is set and `env` is not.
* `desktopDefault` replaces `default` on macOS while Stim Desktop is installed.
* `formerly` is the key an earlier Stim read: a config value under it counts while
* `key` is unset in that layer, and `stim settings` takes it as `key`.
*/
export interface SettingDefinition {
key: string;
Expand All @@ -71,6 +73,9 @@ export interface SettingDefinition {
scopedHomeValue?: string | number | boolean;
ciValue?: string | number | boolean;
desktopDefault?: string;
// compat C35 permanent
formerly?: string;
// compat end
}

export interface SettingEntry {
Expand Down Expand Up @@ -895,7 +900,7 @@ export const SETTINGS: readonly SettingDefinition[] = [
default: false,
env: 'STIM_MAINTENANCE_AUTO_DISCOVER',
description:
'Also let Maintenance and stim gc find checkouts no stim command ran in outside maintenance.discoverRoots: linked worktrees of repositories Stim knows, direct children of folders holding a known project, ~/.codex/worktrees and the home folder scan. Off, they act only on registered workspaces and maintenance.discoverRoots',
'Also let Maintenance and stim gc find checkouts no stim command ran in outside maintenance.managedFolders: linked worktrees of repositories Stim knows, direct children of folders holding a known project, ~/.codex/worktrees and the home folder scan. Off, they act only on registered workspaces and maintenance.managedFolders',
},
{
key: 'maintenance.cleanAutoDiscoveredDependencies',
Expand All @@ -904,15 +909,18 @@ export const SETTINGS: readonly SettingDefinition[] = [
default: false,
env: 'STIM_MAINTENANCE_CLEAN_AUTO_DISCOVERED_DEPENDENCIES',
description:
'Auto discovery only: also let Maintenance and stim gc delete the node_modules and Pods of checkouts that only maintenance.autoDiscover found. It does not affect checkouts where a stim command ran or those maintenance.discoverRoots reaches (a direct child of a root, or a linked worktree inside a root whose main checkout is such a child), whose dependencies are cleaned either way. Off, the auto-found ones stay while the checkout does; their build outputs and finished worktrees are cleaned either way',
'Auto discovery only: also let Maintenance and stim gc delete the node_modules and Pods of checkouts that only maintenance.autoDiscover found. It does not affect checkouts where a stim command ran or those maintenance.managedFolders reaches (a direct child of one of those folders, or a linked worktree inside one whose main checkout is such a child), whose dependencies are cleaned either way. Off, the auto-found ones stay while the checkout does; their build outputs and finished worktrees are cleaned either way',
},
{
key: 'maintenance.discoverRoots',
key: 'maintenance.managedFolders',
type: { kind: 'strings', absolutePaths: true },
scopes: MACHINE,
default: [],
// compat C35 permanent
formerly: 'maintenance.discoverRoots',
// compat end
description:
'Absolute folders (a leading ~ is the home folder) whose direct children Maintenance and stim gc treat as checkouts, even when no stim command ever ran in them, when Stim recognises them as a project it handles, with their linked worktrees inside the folder, whatever maintenance.autoDiscover says. A folder named here is always considered, even under a home dot-folder or the system temporary directory. A discovered checkout follows the rules of a registered workspace, and a scoped STIM_HOME discovers only from this list',
'Absolute folders (a leading ~ is the home folder) whose direct children Maintenance and stim gc treat as checkouts, even when no stim command ever ran in them, when Stim recognises them as a project it handles, with their linked worktrees inside the folder, whatever maintenance.autoDiscover says. A folder named here is always considered, even under a home dot-folder or the system temporary directory. A discovered checkout follows the rules of a registered workspace, and a scoped STIM_HOME discovers only from this list. Formerly maintenance.discoverRoots, still read while this is unset',
},
{
key: 'maintenance.keep',
Expand Down Expand Up @@ -1232,6 +1240,23 @@ export function settingDefinition(key: string): SettingDefinition | null {
return BY_KEY.get(key) ?? null;
}

// compat C35 permanent
const BY_FORMER_KEY: ReadonlyMap<string, SettingDefinition> = new Map(
SETTINGS.flatMap((setting) => (setting.formerly ? [[setting.formerly, setting] as const] : [])),
);

/** The setting an earlier Stim read under `key`, which `stim settings` still takes. */
export function formerSettingDefinition(key: string): SettingDefinition | null {
return BY_FORMER_KEY.get(key) ?? null;
}

/** The value of `setting` in one config layer: under its key, or under `formerly` while the key is unset there. */
export function configuredSettingValue(layer: unknown, setting: SettingDefinition): unknown {
const value = settingValueAt(layer, setting.key);
return value === undefined && setting.formerly ? settingValueAt(layer, setting.formerly) : value;
}
// compat end

export function isLayeredSetting(setting: SettingDefinition): boolean {
return setting.scopes.some((scope) => scope !== 'machine');
}
Expand Down Expand Up @@ -1446,6 +1471,7 @@ export function machineSettingValue(
const explicit = raw !== undefined && raw !== '';
let value: unknown;
let checked: unknown;
let source = key;
if (explicit) {
value = coerceSettingText(setting, raw.trim());
checked = value;
Expand All @@ -1457,15 +1483,19 @@ export function machineSettingValue(
if (container !== undefined && !isJsonObject(container))
return { value: undefined, error: `${group} in the config is not an object` };
}
const configured = settingValueAt(config, key);
const configured = configuredSettingValue(config, setting);
// compat C35 permanent
if (setting.formerly && configured !== undefined && settingValueAt(config, key) === undefined)
source = setting.formerly;
// compat end
checked = configured === undefined ? setting.default : configured;
if (env.STIM_HOME && setting.scopedHomeValue !== undefined) value = setting.scopedHomeValue;
else if (env.CI && setting.ciValue !== undefined) value = setting.ciValue;
else value = checked;
}
const expected = checked === undefined ? null : settingValueError(setting, checked);
const error = expected
? `Invalid ${explicit ? setting.env : key} value ${JSON.stringify(explicit ? raw : checked)}. Expected ${expected}.`
? `Invalid ${explicit ? setting.env : source} value ${JSON.stringify(explicit ? raw : checked)}. Expected ${expected}.`
: null;
return { value, error };
}
11 changes: 10 additions & 1 deletion packages/core/state/settings-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,16 @@ function objectSchema(settings: readonly SettingDefinition[], scope: SettingScop
properties[part] ??= { type: 'object', properties: {}, additionalProperties: false };
node = properties[part];
}
(node.properties as Record<string, JsonSchema>)[parts.at(-1)!] = leafSchema(setting, scope);
const properties = node.properties as Record<string, JsonSchema>;
properties[parts.at(-1)!] = leafSchema(setting, scope);
// compat C35 permanent
if (setting.formerly)
properties[setting.formerly.slice(setting.formerly.lastIndexOf('.') + 1)] = {
...Object.fromEntries(Object.entries(leafSchema(setting, scope)).filter(([name]) => name !== 'x-stim')),
description: `The name Stim 2.0.0 gave ${setting.key}, read while ${setting.key} is unset`,
deprecated: true,
};
// compat end
}
return root;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/stim-cli/src/__tests__/cargo-target-cap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe('the Cargo target cap over a root target/', () => {
beforeEach(() => {
base = realpathSync(mkdtempSync(join(tmpdir(), 'stim-cargo-cap-')));
vi.stubEnv('STIM_HOME', join(base, 'home'));
saveConfig({ version: 2, projects: {}, repos: {}, maintenance: { discoverRoots: [join(base, 'roots')] } });
saveConfig({ version: 2, projects: {}, repos: {}, maintenance: { managedFolders: [join(base, 'roots')] } });
main = join(base, 'roots', 'main');
mkdirSync(main, { recursive: true });
writeFileSync(join(main, 'package.json'), JSON.stringify({ dependencies: { expo: '*' } }));
Expand Down Expand Up @@ -315,7 +315,7 @@ describe('the Cargo target cap over a root target/', () => {
const [action] = (await planCargoTargets({ sizes, settings, pinned: () => false, now: Date.now() })).actions;
if (!action) throw new Error('no trim was planned');

saveConfig({ version: 2, projects: {}, repos: {}, maintenance: { discoverRoots: [] } });
saveConfig({ version: 2, projects: {}, repos: {}, maintenance: { managedFolders: [] } });
const outcome = await trimCargoTargetAction(action);

expect(outcome.status).toBe('kept');
Expand Down Expand Up @@ -343,7 +343,7 @@ describe('the Cargo target cap over a root target/', () => {
version: 2,
projects: {},
repos: {},
maintenance: { discoverRoots: [dotfolder, scratch, ok] },
maintenance: { managedFolders: [dotfolder, scratch, ok] },
});
for (const folder of [dotfolder, scratch, ok]) {
const app = join(folder, 'app');
Expand Down
6 changes: 3 additions & 3 deletions packages/stim-cli/src/__tests__/daemon-ladder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ describe('the pressure ladder', () => {
age(root);
const operation = testContext();
const config = input().config;
config.maintenance = { autoDiscover: false, discoverRoots: [projects] };
config.maintenance = { autoDiscover: false, managedFolders: [projects] };
saveConfig(config);
await marks.markWriter(config)({ path: root, at: Date.now(), lastActivityAt: Date.now() - DAY_MS, kept: null });
expect((await marks.outputMarks(config, operation)).map((mark) => mark.root)).toContain(root);
Expand All @@ -1526,7 +1526,7 @@ describe('the pressure ladder', () => {
lastRung: 1,
between: async () => {
handoffs++;
saveConfig({ ...config, maintenance: { autoDiscover: false, discoverRoots: [] } });
saveConfig({ ...config, maintenance: { autoDiscover: false, managedFolders: [] } });
},
},
pressure('critical'),
Expand All @@ -1548,7 +1548,7 @@ describe('the pressure ladder', () => {
});
const current = input().config;
delete current.projects[root];
current.maintenance = { discoverRoots: [projects] };
current.maintenance = { managedFolders: [projects] };
saveConfig(current);

await runLadder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ beforeEach(() => {
config = {
projects: {},
repos: {},
maintenance: { autoDiscover: false, discoverRoots: [join(holder, 'apps')], cargoTargetMaxGb: 1 },
maintenance: { autoDiscover: false, managedFolders: [join(holder, 'apps')], cargoTargetMaxGb: 1 },
};
saveConfig(config);
});
Expand Down Expand Up @@ -125,7 +125,7 @@ test('a discovered nested app authorizes only its exact holder Cargo candidates
test.each(['route', 'recognition'] as const)('removed %s after marking keeps the saved holder', async (change) => {
await refresh();
if (change === 'route') {
config.maintenance = { autoDiscover: false, discoverRoots: [], cargoTargetMaxGb: 1 };
config.maintenance = { autoDiscover: false, managedFolders: [], cargoTargetMaxGb: 1 };
saveConfig(config);
} else writeFileSync(join(app, 'package.json'), '{}');
expect(await outputMarks(config, testContext())).toEqual([]);
Expand Down Expand Up @@ -165,7 +165,7 @@ test('pins, protected active roots and a route removed after planning keep targe
expect(await trimCargoTargetAction(action, testContext(), false, undefined, holder)).toMatchObject({
status: 'kept',
});
config.maintenance = { autoDiscover: false, discoverRoots: [], cargoTargetMaxGb: 1 };
config.maintenance = { autoDiscover: false, managedFolders: [], cargoTargetMaxGb: 1 };
saveConfig(config);
expect(await trimCargoTargetAction(action, testContext())).toMatchObject({ status: 'kept' });
expect(readFileSync(join(target, 'debug', 'incremental', 'artifact'), 'utf8')).toBe('cargo');
Expand Down
Loading
Loading