Skip to content

fix: make hook-project, embedding, and mesh tests hermetic#734

Open
MarvinFS wants to merge 1 commit into
rohitg00:mainfrom
MarvinFS:fix/hermetic-tests
Open

fix: make hook-project, embedding, and mesh tests hermetic#734
MarvinFS wants to merge 1 commit into
rohitg00:mainfrom
MarvinFS:fix/hermetic-tests

Conversation

@MarvinFS
Copy link
Copy Markdown

@MarvinFS MarvinFS commented May 30, 2026

Three test suites coupled to the developer's environment and failed outside a specific setup. All three fixes are test-only; no production code changes.

test/hook-project.test.ts

Hardcoded the resolved project basename as "agentmemory", so the suite fails for anyone who clones the repo into a directory with a different name (e.g. a fork checked out as agentmemory-lancedb). Now derives the expected basename from the git toplevel the same way resolveProject does. Also fixes a Windows-only assertion that used dir.split('/') instead of path.basename.

test/embedding-provider.test.ts

Asserts "returns null when no API keys are set" and the default embedding dimensions, but the provider resolves keys through getMergedEnv(), which re-reads ~/.agentmemory/.env on every call. A developer with a real key on disk leaks it into those assertions and the tests fail. Now mocks the config env-merge so the tests see only process.env.

test/mesh.test.ts

Let isAllowedUrl() run a real dns.lookup() on *.example.com hostnames, which hangs to the vitest timeout on DNS-restricted CI hosts. Now mocks node:dns/promises so it resolves instantly while isAllowedUrl's own logic still runs.

Verified npm run build clean and npm test green on a fresh main checkout.

Summary by CodeRabbit

  • Tests
    • Improved test reliability by isolating environment-dependent behavior and mocking external dependencies to prevent file system and network access during test execution, ensuring consistent test results across different environments.

Review Change Stack

These three suites coupled to the developer's environment and failed outside a specific setup:

- hook-project.test.ts hardcoded the resolved project basename as "agentmemory", so the suite failed for anyone who cloned the repo into a directory with a different name. Derive the expected basename from the git toplevel the same way resolveProject does, and fix a Windows-only assertion that used dir.split('/') instead of path.basename.
- embedding-provider.test.ts asserted "returns null when no API keys are set" and default embedding dimensions, but the provider resolves keys through getMergedEnv(), which re-reads ~/.agentmemory/.env on every call. A developer with a real key on disk leaked it into those assertions. Mock the config env-merge so the tests see only process.env.
- mesh.test.ts let isAllowedUrl() run a real dns.lookup() on *.example.com hostnames, which hangs to the vitest timeout on DNS-restricted CI hosts. Mock node:dns/promises so it resolves instantly while isAllowedUrl's own logic still runs.

Test-only; no production code changes.

Signed-off-by: MarvinFS <MarvinFS@users.noreply.github.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 30, 2026

@MarvinFS is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 175cdefd-3f4c-4824-a098-bdb6aeccc14e

📥 Commits

Reviewing files that changed from the base of the PR and between fd9e3bd and 1f94ba4.

📒 Files selected for processing (3)
  • test/embedding-provider.test.ts
  • test/hook-project.test.ts
  • test/mesh.test.ts

📝 Walkthrough

Walkthrough

This PR updates three test files to improve test isolation by mocking or deriving environmental factors at runtime. The embedding provider test now mocks the config module to prevent .env file leakage, the hook-project test derives expected basenames at runtime instead of hardcoding them, and the mesh test mocks DNS lookups to avoid network timeouts.

Changes

Test Hermiticity Isolation

Layer / File(s) Summary
Config mock for embedding provider tests
test/embedding-provider.test.ts
vi.mock on ../src/config.js overrides getEnvVar and detectEmbeddingProvider to read only process.env, preventing side effects from on-disk .env files while keeping all existing provider and dimension assertions working.
Hermetic project basename resolution
test/hook-project.test.ts
Add expectedRepoBasename() helper using git rev-parse --show-toplevel with fallback to process.cwd() basename; update all resolver assertions to use runtime-computed repoBasename instead of hardcoded "agentmemory" for git, nested, non-git, and default cases.
DNS mock for mesh tests
test/mesh.test.ts
Mock node:dns/promises.lookup to return a constant public IP address, preventing real DNS network calls and timeouts when isAllowedUrl() validates non-IP hostnames.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • rohitg00/agentmemory#503: Keeps embedding provider tests hermetic by controlling environment variables and config isolation.
  • rohitg00/agentmemory#687: Introduces resolveProject test coverage that this PR makes hermetic through runtime basename resolution.

Suggested reviewers

  • rohitg00

Poem

🐰 Hermetic tests, now pure and free,
No env files or DNS to see!
Runtime basenames dance and play,
Isolation wins the test-suite day!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: making three test suites (hook-project, embedding, and mesh) hermetic by removing environment dependencies.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant