From e2a9d0787413bb2ab7d9c521549782a67807d613 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Fri, 14 Nov 2025 11:55:06 +0000 Subject: [PATCH 1/3] Add global prefix --- integration-tests/js-compute/cleanupAll.js | 117 +++++++++++++-------- integration-tests/js-compute/env.js | 33 +++--- integration-tests/js-compute/test.js | 4 +- 3 files changed, 95 insertions(+), 59 deletions(-) diff --git a/integration-tests/js-compute/cleanupAll.js b/integration-tests/js-compute/cleanupAll.js index 5e4038bc3b..496b6bb57c 100644 --- a/integration-tests/js-compute/cleanupAll.js +++ b/integration-tests/js-compute/cleanupAll.js @@ -14,13 +14,10 @@ const { SECRET_STORE_PREFIX, } = getPrefixes(); -function existingListIds(stores, prefix) { - return stores - .filter( - (store) => - store.name?.startsWith(prefix) || store.Name?.startsWith(prefix), - ) - .map((existing) => existing.id || existing.StoreID); +function existingList(stores, prefix) { + return stores.filter( + (store) => store.name?.startsWith(prefix) || store.Name?.startsWith(prefix), + ); } const startTime = Date.now(); @@ -42,100 +39,130 @@ if (process.env.FASTLY_API_TOKEN === undefined) { } const FASTLY_API_TOKEN = process.env.FASTLY_API_TOKEN; -async function removeConfigStores(links, serviceIds) { +async function removeConfigStores(links, services) { + console.log('Removing config stores...'); const stores = JSON.parse( await zx`fastly config-store list --quiet --json --token $FASTLY_API_TOKEN`, ); - let STORE_IDS = existingListIds(stores, DICTIONARY_PREFIX); - for (const STORE_ID of STORE_IDS) { - await zx`fastly config-store delete --store-id=${STORE_ID} --token $FASTLY_API_TOKEN`; + let dictionaries = existingList(stores, DICTIONARY_PREFIX); + for (const dictionary of dictionaries) { + console.log(`\tDeleting dictionary ${dictionary.name}`); + try { + await zx`fastly config-store delete --store-id=${dictionary.id} --token $FASTLY_API_TOKEN`; + } catch {} } + console.log('All dictionaries removed'); - STORE_IDS = existingListIds(stores, CONFIG_STORE_PREFIX); - for (const STORE_ID of STORE_IDS) { + let configStores = existingList(stores, CONFIG_STORE_PREFIX); + for (const store of configStores) { + console.log(`\tDeleting config store ${store.name}`); try { - await zx`fastly config-store delete --store-id=${STORE_ID} --token $FASTLY_API_TOKEN`; + await zx`fastly config-store delete --store-id=${store.id} --token $FASTLY_API_TOKEN`; } catch {} } + console.log('All config stores removed'); } async function removeKVStores() { + console.log('Removing KV stores...'); const stores = JSON.parse( await zx`fastly kv-store list --quiet --json --token $FASTLY_API_TOKEN`, ).Data; - let STORE_IDS = existingListIds(stores, KV_STORE_PREFIX); - for (const STORE_ID of STORE_IDS) { - await zx`fastly kv-store delete --store-id=${STORE_ID} --quiet --all -y --token $FASTLY_API_TOKEN`; + let kvStores = existingList(stores, KV_STORE_PREFIX); + for (const store of kvStores) { + console.log(`\tDeleting KV store ${store.Name}`); + try { + await zx`fastly kv-store delete --store-id=${store.StoreID} --quiet --all -y --token $FASTLY_API_TOKEN`; + } catch {} } + console.log('All KV stores removed'); } -async function removeSecretStores(serviceIds) { +async function removeSecretStores(services) { + console.log('Removing secret stores...'); const stores = JSON.parse( await zx`fastly secret-store list --quiet --json --token $FASTLY_API_TOKEN`, ); if (!stores) { return; } - const STORE_IDS = existingListIds(stores, SECRET_STORE_PREFIX); - for (const STORE_ID of STORE_IDS) { + const secretStores = existingList(stores, SECRET_STORE_PREFIX); + for (const store of secretStores) { + console.log(`\tDeleting secret store ${store.name}`); try { - await zx`fastly secret-store delete --store-id=${STORE_ID} --token $FASTLY_API_TOKEN`; + await zx`fastly secret-store delete --store-id=${store.id} --token $FASTLY_API_TOKEN`; } catch {} } + console.log('All secret stores removed'); } -async function removeAcls(serviceIds) { - const ACL_IDS = existingListIds( +async function removeAcls(services) { + console.log('Removing ACLs...'); + const acls = existingList( JSON.parse( await zx`fastly compute acl list-acls --quiet --json --token $FASTLY_API_TOKEN`, ).data, ACL_PREFIX, ); - for (const ACL_ID of ACL_IDS) { - await zx`fastly compute acl delete --acl-id=${ACL_ID} --token $FASTLY_API_TOKEN`; + for (const acl of acls) { + console.log(`\tDeleting acl ${acl.name}`); + try { + await zx`fastly compute acl delete --acl-id=${acl.id} --token $FASTLY_API_TOKEN`; + } catch {} } + console.log('All ACLs removed'); } -async function getServiceIds() { +async function getServices() { + console.log('Getting services...'); let services = JSON.parse( await zx`fastly service list --token $FASTLY_API_TOKEN --json`, ); - return services - .filter(({ Name }) => Name.startsWith(SERVICE_PREFIX)) - .map((service) => service.ServiceID); + services = services.filter(({ Name }) => Name.startsWith(SERVICE_PREFIX)); + console.log('Services to delete:'); + for (const service of services) { + console.log('\t', service.Name); + } + return services; } -async function removeServices(serviceIds) { - for (const serviceId of serviceIds) { - await zx`fastly service delete --force --service-id=${serviceId}`; +async function removeServices(services) { + console.log('Removing services...'); + for (const service of services) { + console.log(`\tDeleting service ${service.Name}`); + await zx`fastly service delete --force --service-id=${service.ServiceID}`; } + console.log('ALl services removed'); } -async function removeLinks(serviceIds) { - for (const serviceId of serviceIds) { +async function removeLinks(services) { + console.log('Removing links...'); + for (const service of services) { const links = JSON.parse( - await zx`fastly resource-link list --service-id=${serviceId} --quiet --json --version latest --token $FASTLY_API_TOKEN`, + await zx`fastly resource-link list --service-id=${service.ServiceID} --quiet --json --version latest --token $FASTLY_API_TOKEN`, ); for (const link of links) { + console.log( + `\tDeleting link between service ${service.Name} and resource ${link.name}`, + ); await zx`fastly resource-link delete --version latest --autoclone --id=${link.id} --service-id=${link.service_id} --token $FASTLY_API_TOKEN`; await zx`fastly service-version activate --version latest --service-id=${link.service_id} --token $FASTLY_API_TOKEN`; } } + console.log('All links removed'); } -const serviceIds = await getServiceIds(); -await removeLinks(serviceIds); -await Promise.all([ - removeConfigStores(serviceIds), - removeKVStores(), - removeSecretStores(serviceIds), - removeAcls(serviceIds), -]); -await removeServices(serviceIds); +const services = await getServices(); +await removeLinks(services); +await removeConfigStores(services); +await removeKVStores(); +await removeSecretStores(services); +await removeAcls(services); +await removeServices(services); console.log( - `Tear down has finished! Took ${(Date.now() - startTime) / 1000} seconds to complete`, + `Cleanup has finished! Took ${(Date.now() - startTime) / 1000} seconds to complete`, ); diff --git a/integration-tests/js-compute/env.js b/integration-tests/js-compute/env.js index 93f0e3c15e..1f938018bf 100644 --- a/integration-tests/js-compute/env.js +++ b/integration-tests/js-compute/env.js @@ -1,20 +1,29 @@ +export const GLOBAL_PREFIX = 'js_integration_test_'; + +function applyGlobalPrefix(map) { + for (const key in map) { + map[key] = GLOBAL_PREFIX + map[key]; + } + return map; +} + export function getEnv(serviceName) { - return { + return applyGlobalPrefix({ DICTIONARY_NAME: `aZ2__2${serviceName ? '__' + serviceName.replace(/-/g, '_') : ''}`, - CONFIG_STORE_NAME: `testconfig${serviceName ? '__' + serviceName.replace(/-/g, '_') : ''}`, - KV_STORE_NAME: `example-test-kv-store${serviceName ? '--' + serviceName : ''}`, - SECRET_STORE_NAME: `example-test-secret-store${serviceName ? '--' + serviceName : ''}`, - ACL_NAME: `exampleacl${serviceName ? '__' + serviceName.replace(/-/g, '_') : ''}`, - }; + CONFIG_STORE_NAME: `config${serviceName ? '__' + serviceName.replace(/-/g, '_') : ''}`, + KV_STORE_NAME: `kv-store${serviceName ? '--' + serviceName : ''}`, + SECRET_STORE_NAME: `secret-store${serviceName ? '--' + serviceName : ''}`, + ACL_NAME: `acl${serviceName ? '__' + serviceName.replace(/-/g, '_') : ''}`, + }); } export function getPrefixes() { - return { + return applyGlobalPrefix({ SERVICE_PREFIX: `app-`, DICTIONARY_PREFIX: `aZ2__2`, - CONFIG_STORE_PREFIX: `testconfig`, - KV_STORE_PREFIX: `example-test-kv-store`, - SECRET_STORE_PREFIX: `example-test-secret-store`, - ACL_PREFIX: `exampleacl`, - }; + CONFIG_STORE_PREFIX: `config`, + KV_STORE_PREFIX: `kv-store`, + SECRET_STORE_PREFIX: `secret-store`, + ACL_PREFIX: `acl`, + }); } diff --git a/integration-tests/js-compute/test.js b/integration-tests/js-compute/test.js index 280f357433..4fb9a327f2 100755 --- a/integration-tests/js-compute/test.js +++ b/integration-tests/js-compute/test.js @@ -10,7 +10,7 @@ import { existsSync } from 'node:fs'; import { copyFile, readFile, writeFile } from 'node:fs/promises'; import core from '@actions/core'; import TOML from '@iarna/toml'; -import { getEnv } from './env.js'; +import { getEnv, GLOBAL_PREFIX } from './env.js'; // test environment variable handling process.env.LOCAL_TEST = 'local val'; @@ -81,7 +81,7 @@ const branchName = (await zx`git branch --show-current`).stdout const fixture = !moduleMode ? 'app' : 'module-mode'; // Service names are carefully unique to support parallel runs -const serviceName = `app-${branchName}${aot ? '--aot' : ''}${httpCache ? '--http' : ''}${process.env.SUFFIX_STRING ? '--' + process.env.SUFFIX_STRING : ''}`; +const serviceName = `${GLOBAL_PREFIX}app-${branchName}${aot ? '--aot' : ''}${httpCache ? '--http' : ''}${process.env.SUFFIX_STRING ? '--' + process.env.SUFFIX_STRING : ''}`; let domain, serviceId; const fixturePath = join(__dirname, 'fixtures', fixture); let localServer; From 5e15d4586f627a21e7a5f0a7e683cc6256155b63 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Fri, 14 Nov 2025 13:35:41 +0000 Subject: [PATCH 2/3] Remove resources even if tests fail --- integration-tests/js-compute/test.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/integration-tests/js-compute/test.js b/integration-tests/js-compute/test.js index 4fb9a327f2..abc50bd953 100755 --- a/integration-tests/js-compute/test.js +++ b/integration-tests/js-compute/test.js @@ -136,7 +136,7 @@ if (!local) { core.startGroup('Delete service if already exists'); try { await zx`fastly service delete --quiet --service-name "${serviceName}" --force --token $FASTLY_API_TOKEN`; - } catch {} + } catch { } core.endGroup(); core.startGroup('Build and deploy service'); await zx`npm i`; @@ -170,13 +170,13 @@ await Promise.all([ 27, local ? [ - // we expect it to take ~10 seconds to deploy, so focus on that time - 6000, 3000, 1500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, - 500, 500, 500, 500, 500, 500, 500, 500, 500, - // after more than 20 seconds, means we have an unusually slow build, start backoff before timeout - 1500, - 3000, 6000, 12000, 24000, - ].values() + // we expect it to take ~10 seconds to deploy, so focus on that time + 6000, 3000, 1500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, + 500, 500, 500, 500, 500, 500, 500, 500, 500, + // after more than 20 seconds, means we have an unusually slow build, start backoff before timeout + 1500, + 3000, 6000, 12000, 24000, + ].values() : expBackoff('60s', '10s'), async () => { const response = await request(domain); @@ -275,12 +275,12 @@ for (const chunk of chunks(Object.entries(tests), 100)) { case 'first-chunk-only': for await (const chunk of response.body) { bodyChunks.push(chunk); - response.body.on('error', () => {}); + response.body.on('error', () => { }); break; } break; case 'none': - response.body.on('error', () => {}); + response.body.on('error', () => { }); break; case 'full': default: @@ -435,7 +435,7 @@ if (!local && failed.length) { core.notice(`Tests failed.`); } -if (!local && !skipTeardown && failed.length === 0) { +if (!local && !skipTeardown) { const teardownPath = join(__dirname, 'teardown.js'); if (existsSync(teardownPath)) { core.startGroup('Tear down the extra set-up for the service'); From 51301f70e50d775a13b95dee14609f3b732ec7f6 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Fri, 14 Nov 2025 13:36:00 +0000 Subject: [PATCH 3/3] Format --- integration-tests/js-compute/test.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/integration-tests/js-compute/test.js b/integration-tests/js-compute/test.js index abc50bd953..0caacc5791 100755 --- a/integration-tests/js-compute/test.js +++ b/integration-tests/js-compute/test.js @@ -136,7 +136,7 @@ if (!local) { core.startGroup('Delete service if already exists'); try { await zx`fastly service delete --quiet --service-name "${serviceName}" --force --token $FASTLY_API_TOKEN`; - } catch { } + } catch {} core.endGroup(); core.startGroup('Build and deploy service'); await zx`npm i`; @@ -170,13 +170,13 @@ await Promise.all([ 27, local ? [ - // we expect it to take ~10 seconds to deploy, so focus on that time - 6000, 3000, 1500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, - 500, 500, 500, 500, 500, 500, 500, 500, 500, - // after more than 20 seconds, means we have an unusually slow build, start backoff before timeout - 1500, - 3000, 6000, 12000, 24000, - ].values() + // we expect it to take ~10 seconds to deploy, so focus on that time + 6000, 3000, 1500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, + 500, 500, 500, 500, 500, 500, 500, 500, 500, + // after more than 20 seconds, means we have an unusually slow build, start backoff before timeout + 1500, + 3000, 6000, 12000, 24000, + ].values() : expBackoff('60s', '10s'), async () => { const response = await request(domain); @@ -275,12 +275,12 @@ for (const chunk of chunks(Object.entries(tests), 100)) { case 'first-chunk-only': for await (const chunk of response.body) { bodyChunks.push(chunk); - response.body.on('error', () => { }); + response.body.on('error', () => {}); break; } break; case 'none': - response.body.on('error', () => { }); + response.body.on('error', () => {}); break; case 'full': default: