Skip to content

Commit 68fa552

Browse files
davidgustysclaude
andcommitted
fix(deploy): pass cf --sql and --message as single argv values
`cf d1 query --sql <value>` read SQL that starts with a comment (`-- ...`) as a flag, so seed files with a leading comment failed. Pass `--sql=<value>` and `--message=<value>` as one argument each so a value that starts with "-" is never parsed as an option. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
1 parent a6de782 commit 68fa552

4 files changed

Lines changed: 50 additions & 9 deletions

File tree

‎packages/void/src/cli/cf-version-runner.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,8 @@ export function createCfVersionRunner(options: {
621621
'versions',
622622
'create',
623623
'--prebuilt',
624-
...(operation.message ? ['--message', operation.message] : []),
624+
// One argv item, so a message that starts with "-" is not read as a flag.
625+
...(operation.message ? [`--message=${operation.message}`] : []),
625626
...(operation.secretsFilePath ? ['--secrets-file', operation.secretsFilePath] : []),
626627
...(operation.previewAlias ? ['--preview-alias', operation.previewAlias] : []),
627628
],
@@ -696,7 +697,8 @@ export function createCfVersionRunner(options: {
696697
[
697698
'deploy',
698699
'--prebuilt',
699-
...(operation.message ? ['--message', operation.message] : []),
700+
// One argv item, so a message that starts with "-" is not read as a flag.
701+
...(operation.message ? [`--message=${operation.message}`] : []),
700702
...(operation.secretsFilePath ? ['--secrets-file', operation.secretsFilePath] : []),
701703
],
702704
command.capture,

‎packages/void/src/cli/cloudflare-operation-process.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,8 @@ async function resources(): Promise<Result> {
662662
switch (operation.type) {
663663
case 'd1.execute': {
664664
const database = d1Database(operation.database);
665-
return runCf(['d1', 'query', database.id, '--sql', operation.sql]);
665+
// One argv item, so cf cannot read SQL that starts with "-" (such as a comment) as a flag.
666+
return runCf(['d1', 'query', database.id, `--sql=${operation.sql}`]);
666667
}
667668
case 'd1.migrations.list':
668669
case 'd1.migrations.apply': {
@@ -1116,7 +1117,8 @@ async function workerChanges(): Promise<Result> {
11161117
[
11171118
...(request.type === 'worker.deploy' ? ['deploy'] : ['workers', 'versions', 'create']),
11181119
'--prebuilt',
1119-
...(request.message ? ['--message', request.message] : []),
1120+
// One argv item, so a message that starts with "-" is not read as a flag.
1121+
...(request.message ? [`--message=${request.message}`] : []),
11201122
...(request.secretsFilePath ? ['--secrets-file', request.secretsFilePath] : []),
11211123
],
11221124
directory,

‎packages/void/test/unit/cf-version-runner.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,8 +2547,7 @@ it('preserves activation metadata and sorts cf version history for the existing
25472547
'versions',
25482548
'create',
25492549
'--prebuilt',
2550-
'--message',
2551-
'void:metadata',
2550+
'--message=void:metadata',
25522551
'--preview-alias',
25532552
'void-ready',
25542553
]);

‎packages/void/test/unit/cloudflare-operation-process.test.ts‎

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,45 @@ it('uses pinned cf despite a project-local CLI and preserves D1 results and the
667667
]);
668668
}, 30_000);
669669

670+
it('sends D1 SQL that starts with a comment as one --sql value through the pinned cf', async () => {
671+
const directory = temporaryDirectory('void-cf-d1-comment-sql-');
672+
const bodies: Array<unknown> = [];
673+
const api = await listen(
674+
createServer(async (request, response) => {
675+
let body = '';
676+
for await (const chunk of request) {
677+
body += chunk;
678+
}
679+
bodies.push(JSON.parse(body));
680+
response.setHeader('Content-Type', 'application/json');
681+
response.end(
682+
JSON.stringify({
683+
success: true,
684+
errors: [],
685+
messages: [],
686+
result: [{ results: [], success: true, meta: {} }],
687+
}),
688+
);
689+
}),
690+
);
691+
const configPath = join(directory, 'wrangler.json');
692+
writeFileSync(
693+
configPath,
694+
JSON.stringify({
695+
account_id: 'test-account',
696+
d1_databases: [{ binding: 'DB', database_id: 'test-database' }],
697+
}),
698+
);
699+
const sql = '-- leading comment\nSELECT 1;';
700+
const output = await runOperation(
701+
directory,
702+
{ type: 'd1.execute', database: 'DB', sql, configPath },
703+
tokenEnv(api, 'CF_API_TOKEN'),
704+
);
705+
expect(output.status, output.stderr).toBe(0);
706+
expect(bodies).toEqual([{ sql }]);
707+
}, 30_000);
708+
670709
it('uses the configured HTTP proxy for cf resource requests', async () => {
671710
const directory = temporaryDirectory('void-cf-resource-proxy-');
672711
let proxied = 0;
@@ -1405,7 +1444,7 @@ syncBuiltinESMExports();`,
14051444
{
14061445
type: 'versions.upload',
14071446
configPath,
1408-
message: 'review',
1447+
message: '-review',
14091448
...(interactive ? { interactive } : {}),
14101449
},
14111450
unproxiedEnv(api),
@@ -1418,8 +1457,7 @@ syncBuiltinESMExports();`,
14181457
'versions',
14191458
'create',
14201459
'--prebuilt',
1421-
'--message',
1422-
'review',
1460+
'--message=-review',
14231461
]);
14241462
if (interactive) {
14251463
expect(called.stdio).toBe('inherit');

0 commit comments

Comments
 (0)