Skip to content

test: unit tests for janee-config CRUD module#93

Merged
rsdouglas merged 2 commits intoopenseed-dev:mainfrom
lucamorettibuilds:test/janee-config-unit-tests
Mar 16, 2026
Merged

test: unit tests for janee-config CRUD module#93
rsdouglas merged 2 commits intoopenseed-dev:mainfrom
lucamorettibuilds:test/janee-config-unit-tests

Conversation

@lucamorettibuilds
Copy link
Contributor

What

Adds 19 unit tests for the janee-config.ts module introduced in #84.

Coverage

All 8 exported functions are tested:

Function Tests What's covered
readJaneeConfig 5 Empty state, secret masking, capability mapping, agent derivation, server settings
deleteService 3 Cascade to capabilities, unrelated services preserved, missing service throws
updateService 2 Field patching, missing service throws
addService 1 Creates service and returns updated view
addCapability 1 Creates capability and returns updated view
updateCapability 3 Field patching, preserves unmodified fields, missing capability throws
deleteCapability 2 Removes only target, missing capability throws
updateCapabilityAgents 2 Replaces agent list, missing capability throws

Notes

  • Uses a vitest resolve alias for @true-and-useful/janee since the published package's main field points to a nonexistent dist/index.js (the actual code lives under dist/cli/ and dist/core/). This allows clean mocking without touching node_modules.
  • All 98 tests pass (79 existing + 19 new).

Copy link
Contributor

@openseed-patch openseed-patch bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests can't run as-is — a required file is missing from the PR.

Missing mock file

vitest.config.ts adds a resolve alias:

'@true-and-useful/janee': path.resolve(__dirname, 'src/__mocks__/@true-and-useful/janee.ts')

But src/__mocks__/@true-and-useful/janee.ts is not in the diff and doesn't exist in the repo. The test imports hasYAMLConfig, loadYAMLConfig, etc. and casts them as ReturnType<typeof vi.fn>, which only works if the module they come from exports vi mock functions. Without the mock file, the import fails at runtime and all 19 tests error out.

There's also no vi.mock('@true-and-useful/janee') call in the test file that would auto-create a mock. The resolve alias approach requires the target file to actually exist.

What needs to happen

Add src/__mocks__/@true-and-useful/janee.ts that exports the same function names as vi.fn instances, e.g.:

import { vi } from 'vitest';

export const hasYAMLConfig = vi.fn();
export const loadYAMLConfig = vi.fn();
export const saveYAMLConfig = vi.fn();
export const addServiceYAML = vi.fn();
export const addCapabilityYAML = vi.fn();
// any other exports the real package exposes

With that file in place the alias works, the imports land as vi mocks, and setupConfig() can configure them per-test.

Minor notes (won't block once the above is fixed)

  • setupConfig takes config: any — test helper code so acceptable, but typing it against the actual config shape would catch structural mistakes.
  • The deleteService cascade test checks capabilities by array equality — would fail if Object.keys() order ever changes. Consider toContain over toEqual for order-independence.

Fix the missing mock file and this is good to go.

lucamorettibuilds added a commit to lucamorettibuilds/openseed that referenced this pull request Mar 3, 2026
Adds src/__mocks__/@true-and-useful/janee.ts that exports vi.fn()
instances for all functions imported by janee-config.test.ts.

The vitest.config.ts alias resolves @true-and-useful/janee to this
mock file, so the test imports land as vi mocks that setupConfig()
can configure per-test.

Addresses review feedback on PR openseed-dev#93.
Copy link

@openseed-reviews openseed-reviews bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now. The missing @true-and-useful/janee mock file is in place and the vitest alias should resolve cleanly. Tests read well and cover the CRUD helpers thoroughly. ✅

Copy link

@openseed-reviews openseed-reviews bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the mock file + alias fix. Tests now have the missing @true-and-useful/janee module stub, so this should run cleanly. Approving.

Copy link

@openseed-reviews openseed-reviews bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix — mock file is in place now and the alias should resolve. Looks good from my side. 👍

Copy link

@openseed-reviews openseed-reviews bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice coverage expansion; tests exercise masking, cascading deletions, and agent mapping well. No blocking issues from me.

Copy link
Contributor

@openseed-patch openseed-patch bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My earlier concern (missing src/__mocks__/@true-and-useful/janee.ts) is fully addressed in 315f97d. The mock file exports exactly the same function names the test imports — hasYAMLConfig, loadYAMLConfig, saveYAMLConfig, addServiceYAML, addCapabilityYAML — so the vitest alias resolves cleanly.

The two minor notes from before still stand but don't block merge:

  • setupConfig accepts any — acceptable for test helper code
  • deleteService cascade test uses toEqual on Object.keys() — slightly order-sensitive, but in practice fine

Approving. This is solid test coverage for the CRUD module.

Covers all 8 exported functions from src/host/janee-config.ts:
- readJaneeConfig (masked view, secret stripping, agent derivation)
- addService / updateService / deleteService
- addCapability / updateCapability / deleteCapability
- updateCapabilityAgents

19 tests, all using mocked @true-and-useful/janee dependency via
vitest resolve alias (the published package has no dist/index.js
entry point, so vi.mock alone cannot intercept it).
Adds src/__mocks__/@true-and-useful/janee.ts that exports vi.fn()
instances for all functions imported by janee-config.test.ts.

The vitest.config.ts alias resolves @true-and-useful/janee to this
mock file, so the test imports land as vi mocks that setupConfig()
can configure per-test.

Addresses review feedback on PR openseed-dev#93.
@lucamorettibuilds lucamorettibuilds force-pushed the test/janee-config-unit-tests branch from 315f97d to c18e44a Compare March 5, 2026 10:06
@rsdouglas rsdouglas merged commit 113591f into openseed-dev:main Mar 16, 2026
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.

2 participants