Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
ci(dashboard): bound the unit tests and add on-demand coverage
Yudhi Armyndharis42c4b9927040
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex bdc23c394..04b4aab5f 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -305,7 +305,9 @@ jobs:- name: Build dashboardrun: cd dashboard && npm run build+ # --test-timeout in test:unit fails a hung test by name; this bounds a hang it cannot see.- name: Run dashboard unit tests+ timeout-minutes: 10run: cd dashboard && npm run test:unit# The repo ships several host-level shell smoke scripts (scripts/smoke-test-*.sh, plusdiff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 2af2fa07b..0511939f6 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -283,7 +283,9 @@ jobs:- name: Build dashboardrun: cd dashboard && npm run build+ # --test-timeout in test:unit fails a hung test by name; this bounds a hang it cannot see.- name: Run dashboard unit tests+ timeout-minutes: 10run: cd dashboard && npm run test:unit# Mirrors ci.yml's scripts-smoke job, which had no counterpart here at all: the shell scripts thatdiff --git a/dashboard/package.json b/dashboard/package.jsonindex 624765945..7537e06ee 100644--- a/dashboard/package.json+++ b/dashboard/package.json@@ -12,8 +12,9 @@"typecheck": "tsc --noEmit -p tsconfig.test.json","preview": "vite preview","i18n:check": "node scripts/check-i18n-parity.mjs",- "test": "node --experimental-strip-types --test \"src/**/*.test.ts\"",- "test:unit": "node --experimental-strip-types --test \"src/**/*.test.ts\""+ "test": "npm run test:unit",+ "test:unit": "node --experimental-strip-types --test --test-timeout=120000 \"src/**/*.test.ts\"",+ "test:cov": "node --experimental-strip-types --test --test-timeout=120000 --experimental-test-coverage --test-coverage-exclude=\"src/**/*.test.ts\" --test-coverage-exclude=\"src/test-helpers/**\" \"src/**/*.test.ts\""},"dependencies": {"@tanstack/react-query": "^5.103.1",diff --git a/docs/09-testing-strategy.md b/docs/09-testing-strategy.mdindex 552a3d5cc..ceec6643e 100644--- a/docs/09-testing-strategy.md+++ b/docs/09-testing-strategy.md@@ -52,6 +52,7 @@ npm --prefix dashboard run test:unit| `cd dashboard && npm run lint` | Run dashboard ESLint || `cd dashboard && npm run typecheck` | Type-check dashboard test files || `cd dashboard && npm run test:unit` | Run dashboard pure utility/unit tests |+| `cd dashboard && npm run test:cov` | Measure dashboard unit-test coverage (on demand, no enforced floor) || `cd dashboard && npm run i18n:check` | Verify dashboard locale key parity || `cd dashboard && npm run build` | Type-check and build the dashboard || `cd sdk/javascript && npm test && npm run typecheck` | Type-check and unit-test the JavaScript SDK |@@ -256,6 +257,9 @@ The stricter scoped gates protect security-sensitive code and high-risk boundarysecurity, engine-adapter, or integration-fabric behavior, add focused regression tests instead of relyingon broad integration coverage.+The dashboard is outside these floors. `npm --prefix dashboard run test:cov` measures its coverage on+demand (Node's built-in coverage, test files and `src/test-helpers/` excluded); no CI floor is enforced.+## 9.6 CI ChecksMain CI is defined in `.github/workflows/ci.yml`. A new push to a pull request cancels that pulldiff --git a/src/common/ci-privilege-gate.spec.ts b/src/common/ci-privilege-gate.spec.tsindex 47a7af408..5817ad293 100644--- a/src/common/ci-privilege-gate.spec.ts+++ b/src/common/ci-privilege-gate.spec.ts@@ -441,3 +441,39 @@ describe('every workflow job declares a bounded timeout', () => {expect(unbounded).toEqual([]);});});++/**+ * The dashboard's unit tests stalled for half an hour on a leaked timer and still reported green,+ * because node:test waits for the event loop to drain and nothing bounded it. The per-test timeout+ * turns that into a failure naming the file; the step timeout backstops a hang the runner cannot+ * attribute to a test.+ */+describe('the dashboard unit tests are bounded', () => {+ const dashboardScripts = (): Record<string, string> =>+ (+ JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', 'dashboard', 'package.json'), 'utf8')) as {+ scripts: Record<string, string>;+ }+ ).scripts;++ it('runs test:unit and test:cov with a per-test timeout, and test through test:unit', () => {+ const scripts = dashboardScripts();+ expect(scripts['test:unit']).toMatch(/--test-timeout=\d+/);+ expect(scripts['test:cov']).toMatch(/--test-timeout=\d+/);+ // --test-force-exit would hide the very leak the timeout exposes.+ expect(scripts['test:unit']).not.toContain('--test-force-exit');+ expect(scripts.test).toBe('npm run test:unit');+ });++ it.each(['ci.yml', 'release.yml'])('%s bounds the dashboard unit test step', file => {+ type TimedStep = Step & { 'timeout-minutes'?: unknown };+ const workflow = yaml.load(fs.readFileSync(path.join(workflowDir, file), 'utf8')) as {+ jobs?: Record<string, { steps?: TimedStep[] }>;+ };+ const steps = Object.values(workflow.jobs ?? {})+ .flatMap(job => job.steps ?? [])+ .filter(step => executableLines(step.run ?? '').includes('npm run test:unit'));+ expect(steps.length).toBe(1);+ expect(steps[0]['timeout-minutes']).toEqual(expect.any(Number));+ });+});