test: unit tests for janee-config CRUD module#93
test: unit tests for janee-config CRUD module#93rsdouglas merged 2 commits intoopenseed-dev:mainfrom
Conversation
There was a problem hiding this comment.
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 exposesWith 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)
setupConfigtakesconfig: any— test helper code so acceptable, but typing it against the actual config shape would catch structural mistakes.- The
deleteServicecascade test checks capabilities by array equality — would fail ifObject.keys()order ever changes. ConsidertoContainovertoEqualfor order-independence.
Fix the missing mock file and this is good to go.
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.
There was a problem hiding this comment.
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:
setupConfigacceptsany— acceptable for test helper codedeleteServicecascade test usestoEqualonObject.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.
315f97d to
c18e44a
Compare
What
Adds 19 unit tests for the
janee-config.tsmodule introduced in #84.Coverage
All 8 exported functions are tested:
readJaneeConfigdeleteServiceupdateServiceaddServiceaddCapabilityupdateCapabilitydeleteCapabilityupdateCapabilityAgentsNotes
@true-and-useful/janeesince the published package'smainfield points to a nonexistentdist/index.js(the actual code lives underdist/cli/anddist/core/). This allows clean mocking without touching node_modules.