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
5 changes: 4 additions & 1 deletion packages/void/src/cli/cf-version-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,10 @@ export async function uploadPinnedCloudflareVersion(options: {
modules,
compatibility_date: config.compatibilityDate,
compatibility_flags: config.compatibilityFlags,
package_dependencies: await readPackageDependencies(options.output.directory),
package_dependencies:
process.env.CLOUDFLARE_DEPENDENCIES_INSTRUMENTATION?.toLowerCase() === 'false'
? undefined
: await readPackageDependencies(options.output.directory),
bindings,
...(config.limits
? { limits: { cpu_ms: config.limits.cpuMs, subrequests: config.limits.subrequests } }
Expand Down
25 changes: 21 additions & 4 deletions packages/void/test/unit/cf-version-runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ import {
// globals, and Vitest clears every mock's call history whenever another test starts.
const it = serialIt.concurrent;

it.each([false, true])(
'uploads the same package versions as real cf when preserving secrets (atomic=%s)',
serialIt.each([false, true])(
'matches cf package versions and honors the opt-out when preserving secrets (atomic=%s)',
async (atomic) => {
const activeVersionId = '11111111-1111-4111-8111-111111111111';
const root = mkdtempSync(join(tmpdir(), 'void-cf-package-context-'));
Expand Down Expand Up @@ -164,7 +164,9 @@ it.each([false, true])(
response.writeHead(200, { 'Content-Type': 'application/json' });
response.end(JSON.stringify({ success: true, errors: [], messages: [], result }));
});
const instrumentationEnv = 'CLOUDFLARE_DEPENDENCIES_INSTRUMENTATION';
try {
vi.stubEnv(instrumentationEnv, undefined);
const apiBaseUrl = await listen(server);
// The fake response need only acknowledge the upload, not cf's subsequent presentation.
const result = await pinnedCf(apiBaseUrl)(['workers', 'versions', 'create', '--prebuilt'], {
Expand All @@ -188,15 +190,16 @@ it.each([false, true])(
requiredNames: [],
})!(activeVersionId, [{ name: 'AUTH_SECRET', type: 'secret_text' }]),
).toBe(true);
await uploadPinnedCloudflareVersion({
const uploadOptions = {
output: prepared!,
accountId: 'account-id',
apiBaseUrl,
workerName: 'void-test',
token: 'synthetic-token',
atomic,
verifyUploader: () => true,
});
};
await uploadPinnedCloudflareVersion(uploadOptions);
expect(uploads).toHaveLength(2);
expect(uploads[1].package_dependencies).toEqual(uploads[0].package_dependencies);
expect(uploads[1].bindings).toContainEqual({
Expand All @@ -205,7 +208,21 @@ it.each([false, true])(
version_id: activeVersionId,
});
expect(uploads[1].modules).toEqual([expect.objectContaining({ name: 'index.js' })]);

vi.stubEnv(instrumentationEnv, atomic ? 'FaLsE' : 'false');
await uploadPinnedCloudflareVersion(uploadOptions);
expect(uploads).toHaveLength(3);
expect(uploads[2]).not.toHaveProperty('package_dependencies');
const optOutBody = { ...uploads[1] };
delete optOutBody.package_dependencies;
expect(uploads[2]).toEqual(optOutBody);

vi.stubEnv(instrumentationEnv, 'TrUe');
await uploadPinnedCloudflareVersion(uploadOptions);
expect(uploads).toHaveLength(4);
expect(uploads[3]).toEqual(uploads[1]);
} finally {
vi.unstubAllEnvs();
await prepared!.dispose();
}
},
Expand Down