From db15187ef18340c1ea9cc20ebf9a4f4149652331 Mon Sep 17 00:00:00 2001 From: Cristian Greco Date: Fri, 9 Oct 2026 11:07:41 +0100 Subject: [PATCH 1/8] Detect unused code and dependencies with knip Add knip with a documented config, an npm script and a Checks job, and fix what it reports: remove two @types packages whose libraries now ship their own types, delete unused test helpers and an unused type, and drop export from internal symbols only used in their own file. Nothing exported from a package's index.ts changes. --- .github/workflows/checks.yml | 18 + AGENTS.md | 2 +- knip.jsonc | 33 + package-lock.json | 1106 +++++++++++++++-- package.json | 2 + .../modules/ollama/src/ollama-container.ts | 2 +- packages/modules/rabbitmq/package.json | 1 - packages/testcontainers/package.json | 1 - .../clients/compose/types.ts | 2 +- .../clients/container/types.ts | 2 +- .../src/container-runtime/index.ts | 2 +- packages/testcontainers/src/types.ts | 4 +- packages/testcontainers/src/utils/labels.ts | 6 +- .../testcontainers/src/utils/test-helper.ts | 31 - .../src/wait-strategies/utils/health-check.ts | 4 +- 15 files changed, 1093 insertions(+), 123 deletions(-) create mode 100644 knip.jsonc diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index cf2ba23b3..1d3504da7 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -80,6 +80,23 @@ jobs: WORKSPACE_PATH: ${{ steps.npm-install-modules.outputs.workspace_path }} run: npm run lint:ci + knip: + # Knip analyses every workspace together, so it runs once with a full install instead of per module. + name: Knip + runs-on: ubuntu-24.04 + steps: + - name: Code checkout + uses: actions/checkout@v7 + - name: Install NodeJS + uses: actions/setup-node@v6 + with: + node-version: 24.x + package-manager-cache: false + - name: Install dependencies + run: npm ci --ignore-scripts + - name: Find unused files, exports and dependencies + run: npm run knip + compile: if: ${{ needs.detect-modules.outputs.modules_count != '0' }} name: Compile @@ -207,6 +224,7 @@ jobs: needs: - detect-modules - lint + - knip - compile - smoke-test - smoke-test-bun diff --git a/AGENTS.md b/AGENTS.md index 043db2c2d..7d2e458c0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -86,7 +86,7 @@ reviewers can follow the reasoning. 1. Start from `main`. 2. Create a branch prefixed with `/` (for example `claude/fix-exec-output-truncation`). The PR title must not carry such prefixes (see step 9). 3. Implement scoped changes only. -4. Run required checks: `npm run format`, `npm run lint`, `npm run check-compiles` when touching `packages/testcontainers` APIs consumed by modules, and targeted tests. +4. Run required checks: `npm run format`, `npm run lint`, `npm run knip`, `npm run check-compiles` when touching `packages/testcontainers` APIs consumed by modules, and targeted tests. - When working in a fresh git worktree, dependencies are not installed (`node_modules` is absent), so verification commands (tests, `lint`, `format`, `check-compiles`) will fail with "Cannot find module" errors. Run `npm ci` once before verifying. `npm ci` only populates `node_modules` and must not modify `package-lock.json`; if it does, treat that as drift to investigate. 5. Verify git diff only contains intended files. 6. Never commit, push, or post on GitHub (issues, PRs, or comments) without first sharing the proposed diff/message and getting explicit user approval. diff --git a/knip.jsonc b/knip.jsonc new file mode 100644 index 000000000..4d272cd79 --- /dev/null +++ b/knip.jsonc @@ -0,0 +1,33 @@ +{ + "$schema": "https://unpkg.com/knip@6/schema-jsonc.json", + "workspaces": { + ".": { + // Loaded by a