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
3 changes: 2 additions & 1 deletion docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ pnpm verify
and `scripts/check-owning-pages.mjs` against temporary Git branches and pull request descriptions. The live `docs:check`
validates required entry points, root and package instruction aliases, repository-contained local links, heading
fragments, reference-style definitions and uses, code-example exclusion, canonical page reachability, and the root
`AGENTS.md` line budget.
`AGENTS.md` line budget. It skips Git-ignored `dist`, `.turbo`, and `coverage` output, whose staged copies such as the
packaged VS Code README carry links that resolve only after publishing.

## CI and task caching

Expand Down
5 changes: 4 additions & 1 deletion packages/sdk/test/discovery-http-capabilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
region,
requests,
scenario,
settleOnFakeTimers,
useDiscoveryHttpHarness,
} from './helpers/discovery-http.js';

Expand Down Expand Up @@ -82,8 +83,10 @@ describe('live capability outcomes', () => {

it('reports Hub enrollment as error when the enrollment status keeps failing', async () => {
vi.spyOn(Math, 'random').mockReturnValue(0);
vi.useFakeTimers();
scenario.transientOperation = 'ListEnrollmentStatuses';
const result = await discoverRules(['CLDBRN-AWS-COSTOPTIMIZATIONHUB-1']);
const pending = discoverRules(['CLDBRN-AWS-COSTOPTIMIZATIONHUB-1']);
const result = await settleOnFakeTimers(pending, 'ListEnrollmentStatuses');

expect(capabilitiesOf(result)).toEqual([
{
Expand Down
5 changes: 4 additions & 1 deletion packages/sdk/test/discovery-http-compute-optimizer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
expectReadOnlyRequests,
requests,
scenario,
settleOnFakeTimers,
useDiscoveryHttpHarness,
useLambdaScenario,
} from './helpers/discovery-http.js';
Expand Down Expand Up @@ -78,10 +79,12 @@ describe('live capability outcomes', () => {
};
scenario.transientOperation = 'GetLambdaFunctionRecommendations';
scenario.transientHostname = 'compute-optimizer.us-east-1.amazonaws.com';
const result = await discoverRules(['CLDBRN-AWS-LAMBDA-4'], {
vi.useFakeTimers();
const pending = discoverRules(['CLDBRN-AWS-LAMBDA-4'], {
mode: 'regions',
regions: ['eu-west-1', 'us-east-1'],
});
const result = await settleOnFakeTimers(pending, 'GetLambdaFunctionRecommendations');

expect(capabilitiesOf(result)).toEqual([
{
Expand Down
16 changes: 16 additions & 0 deletions packages/sdk/test/helpers/discovery-http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,22 @@ export const volumeAttempt = () =>
.map((message) => JSON.parse(message.slice(13)))
.find((attempt) => attempt.operation === 'DescribeVolumes');

/**
* Settles discovery started under fake timers, skipping its admission waits and retry backoff.
*
* @param pending - Discovery started after `vi.useFakeTimers()`.
* @param operation - The AWS operation whose first request precedes the backoff.
* @returns The settled discovery result.
*/
export const settleOnFakeTimers = async <T>(pending: Promise<T>, operation: string): Promise<T> => {
// Each waitFor check also advances fake timers, moving the admission waits that precede the request.
await vi.waitFor(() => expect(requests.some((request) => request.operation === operation)).toBe(true), {
timeout: 10_000,
});
await vi.advanceTimersByTimeAsync(120_000);
return pending;
};

// Public cancellation rejects promptly; let the detached request release its
// SQLite lease before this fixture deletes its private admission directory.
/** Waits until a cancelled catalog request releases its admission lease. */
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { availableParallelism } from 'node:os';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vitest/config';

Expand All @@ -13,6 +14,9 @@ export default defineConfig({
// Loaded CI runners stretch them several times over; keep budgets above that instead of Vitest's 5s default.
testTimeout: 30_000,
hookTimeout: 30_000,
// Those suites mostly wait on timers, so more workers than CPUs keep the other files moving beside them. Vitest caps
// percentage values at the CPU count, so compute the number.
maxWorkers: Math.ceil(availableParallelism() * 1.5),
coverage: {
provider: 'v8',
},
Expand Down
6 changes: 5 additions & 1 deletion scripts/check-docs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ const exists = async (path) => {
}
};

// Dependencies and generated output are Git-ignored; staged copies such as a packaged README carry links that resolve
// only after publishing.
const skippedDirectories = new Set(['.git', 'node_modules', 'dist', '.turbo', 'coverage']);

const walk = async (directory) => {
const paths = [];
for (const entry of await readdir(directory, { withFileTypes: true })) {
if (entry.name === '.git' || entry.name === 'node_modules') continue;
if (skippedDirectories.has(entry.name)) continue;
const path = resolve(directory, entry.name);
paths.push(path);
if (entry.isDirectory()) paths.push(...(await walk(path)));
Expand Down
10 changes: 10 additions & 0 deletions test/docs-check.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ test('accepts a valid repository and its root and package aliases', async () =>
assert.match(result.stdout, /Documentation check passed/);
});

test('ignores generated build output such as a staged package README', async () => {
const root = await createFixtureRepository();
await mkdir(join(root, 'packages/example/dist/media'), { recursive: true });
await writeFile(join(root, 'packages/example/dist/media/README.md'), '[Guide](../../../docs/missing.md)\n');

const result = await runChecker(root);

assert.equal(result.code, 0, result.stderr);
});

test('rejects a missing required documentation entry point', async () => {
const root = await createFixtureRepository();
await rm(join(root, 'docs/README.md'));
Expand Down
Loading