Skip to content

Commit 4460ea3

Browse files
committed
fix(configs): retain optional package update semantics
1 parent 3b2a3c5 commit 4460ea3

4 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎src/routes/api/configs/+server.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export const POST: RequestHandler = async ({ platform, cookies, request }) => {
146146
}
147147

148148
const id = generateId();
149-
const selectedPackages = normalizePackages(packages || [], snapshot?.packages, false);
149+
const selectedPackages = normalizePackages(packages || [], snapshot?.packages, packages === undefined);
150150

151151
try {
152152
await createConfig(env.DB, {

‎src/routes/api/configs/[slug]/+server.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export const PUT: RequestHandler = async ({ platform, cookies, params, request }
187187

188188
let snapshotToSave = snapshot;
189189
let selectedPackages: ReturnType<typeof normalizePackages> | undefined;
190-
if (packages !== undefined) {
190+
if (packages !== undefined && packages !== null) {
191191
let previousSnapshot = null;
192192
if (snapshot === undefined && existing.snapshot) {
193193
try {

‎src/routes/api/configs/[slug]/server.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,3 +425,14 @@ describe('package source save round-trip', () => {
425425
expect(empty.config.packages).toEqual([]);
426426
});
427427
});
428+
429+
describe('optional package updates', () => {
430+
it('retains the software selection when packages is null', async () => {
431+
await seed(db, { users: [userRow()], configs: [mockConfig], api_tokens: [mockApiToken] });
432+
const updated = await call(PUT, callOpts({ method: 'PUT', token: mockApiToken.token, body: { packages: null } }));
433+
expect(updated.status).toBe(200);
434+
const read = await call(GET, callOpts({ token: mockApiToken.token }));
435+
const data = (await read.json()) as { config: { packages: unknown[] } };
436+
expect(data.config.packages).toEqual(JSON.parse(mockConfig.packages));
437+
});
438+
});

‎src/routes/api/configs/server.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,22 @@ describe('snapshot source normalization', () => {
302302
]);
303303
});
304304
});
305+
306+
describe('snapshot-only config creation', () => {
307+
it('preserves sources when the software selection is omitted', async () => {
308+
await seed(db, { users: [userRow()], api_tokens: [mockApiToken] });
309+
const response = await call(POST, {
310+
url: baseUrl,
311+
method: 'POST',
312+
token: mockApiToken.token,
313+
body: { name: 'Sources only', snapshot: { packages: { taps: ['example/tools'] } } }
314+
});
315+
expect(response.status).toBe(201);
316+
const created = (await response.json()) as { slug: string };
317+
const list = await call(GET, { url: baseUrl, token: mockApiToken.token });
318+
const data = (await list.json()) as { configs: { slug: string; packages: { name: string; type: string }[] }[] };
319+
expect(data.configs.find((config) => config.slug === created.slug)?.packages).toEqual([
320+
{ name: 'example/tools', type: 'tap' }
321+
]);
322+
});
323+
});

0 commit comments

Comments
 (0)