diff --git a/dev/local/env-sync/index.ts b/dev/local/env-sync/index.ts index 8c3c84221d..f1514e5532 100644 --- a/dev/local/env-sync/index.ts +++ b/dev/local/env-sync/index.ts @@ -79,7 +79,7 @@ async function syncEnvVars(options: { plan.envLocalAutoCreates.length > 0 ? await computePlanAsync(repoRoot, serviceFilter, refreshSourceBackedSecrets) : plan; - await applyPlan(applyReadyPlan, repoRoot, { missingSecretsOnly }); + await applyPlan(applyReadyPlan, repoRoot); console.log(`\n${GREEN}✓ Applied${RESET}`); } else { console.log('Skipped.'); diff --git a/dev/local/env-sync/output.test.ts b/dev/local/env-sync/output.test.ts index 856c9ce138..486435453a 100644 --- a/dev/local/env-sync/output.test.ts +++ b/dev/local/env-sync/output.test.ts @@ -19,11 +19,11 @@ function secretCreate(workerDir: string, secretName: string): SecretStoreAutoCre }; } -test('creates missing secrets concurrently across stores and rechecks existing secrets', async () => { +test('creates planned secrets concurrently across stores without re-listing them', async () => { const repoRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'env-sync-output-')); - const existing = secretCreate('services/event-service', 'EXISTING_SECRET'); - const missing = secretCreate('services/model-eval-ingest', 'MISSING_SECRET'); - for (const create of [existing, missing]) { + const first = secretCreate('services/event-service', 'FIRST_SECRET'); + const second = secretCreate('services/model-eval-ingest', 'SECOND_SECRET'); + for (const create of [first, second]) { fs.mkdirSync(path.join(repoRoot, create.workerDir, '.wrangler'), { recursive: true }); } @@ -33,7 +33,7 @@ test('creates missing secrets concurrently across stores and rechecks existing s envDevLocalChanges: [], envLocalAutoCreates: [], secretStoreWarnings: [], - secretStoreAutoCreates: [existing, missing], + secretStoreAutoCreates: [first, second], consistencyWarnings: [], execWarnings: [], missingEnvLocal: false, @@ -44,20 +44,13 @@ test('creates missing secrets concurrently across stores and rechecks existing s try { await applyPlan(plan, repoRoot, { concurrency: 2, - missingSecretsOnly: true, - runWrangler: async (_repoRoot, workerDir, args, input) => { + runWrangler: async (_repoRoot, _workerDir, args, input) => { active++; maxActive = Math.max(maxActive, active); await new Promise(resolve => setTimeout(resolve, 20)); active--; - if (args.includes('list')) { - return { - status: 0, - stderr: '', - stdout: workerDir === existing.workerDir ? 'EXISTING_SECRET\n' : '', - }; - } + assert.ok(!args.includes('list')); assert.ok(input?.startsWith('value-for-')); assert.ok(!args.some(arg => arg.startsWith('value-for-'))); created.push(args[args.indexOf('--name') + 1] ?? ''); @@ -66,7 +59,7 @@ test('creates missing secrets concurrently across stores and rechecks existing s }); assert.equal(maxActive, 2); - assert.deepEqual(created, ['MISSING_SECRET']); + assert.deepEqual(created.sort(), ['FIRST_SECRET', 'SECOND_SECRET']); } finally { fs.rmSync(repoRoot, { recursive: true, force: true }); } diff --git a/dev/local/env-sync/output.ts b/dev/local/env-sync/output.ts index dedab1bd6d..0ad0332989 100644 --- a/dev/local/env-sync/output.ts +++ b/dev/local/env-sync/output.ts @@ -273,7 +273,6 @@ type WranglerRunner = typeof runWrangler; type ApplyPlanOptions = { concurrency?: number; - missingSecretsOnly?: boolean; runWrangler?: WranglerRunner; }; @@ -331,26 +330,6 @@ function resolveWranglerPersistenceDir(repoRoot: string, workerDir: string): str } } -async function secretExists( - create: SecretStoreAutoCreate, - repoRoot: string, - runner: WranglerRunner = runWrangler -): Promise { - const result = await runner(repoRoot, create.workerDir, [ - 'secrets-store', - 'secret', - 'list', - create.binding.store_id, - ]); - if (result.status !== 0) { - const errorOutput = result.stderr.trim(); - throw new Error( - `Failed to list Secrets Store secrets for ${create.workerDir}${errorOutput ? `: ${errorOutput}` : ''}` - ); - } - return result.stdout.includes(create.binding.secret_name); -} - async function applySecretsStoreAutoCreates( creates: SecretStoreAutoCreate[], repoRoot: string, @@ -377,13 +356,7 @@ async function applySecretsStoreAutoCreates( `Secrets Store for ${group[0]?.workerDir ?? persistenceDir}`, async () => { for (const create of group) { - if ( - options.missingSecretsOnly && - (await secretExists(create, repoRoot, options.runWrangler)) - ) { - console.log(` ✓ ${create.binding.secret_name} already exists`); - continue; - } + // The plan already filtered out secrets that exist locally, so no re-listing here. await createSecretsStoreSecret( repoRoot, create.workerDir,