stack/packages/stack-shared/src/config-authoring.test.ts
Mantra 37a69b0f0a
make config typesafe (#1254)
## Summary
- add a public `defineStackConfig` helper and `StackConfig` type for
nested config authoring
- emit helper-based nested config files from the CLI and local emulator
- update type coverage and e2e expectations for the new `stack.config`
format

## Testing
- pnpm --filter ./packages/stack-shared typecheck
- pnpm --filter ./packages/stack-cli typecheck
- pnpm --filter ./apps/backend typecheck
- pnpm --filter ./apps/e2e typecheck

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
  * Type-safe configuration API with compile-time validation
  * New config rendering utility for producing typed config files
* Public local-emulator settings and a public helper to detect emulator
mode
  * Added --overwrite flag for config pull

* **Improvements**
* Stronger validation and clearer errors for invalid or conflicting
config shapes
  * Config output now includes explicit TypeScript typing

* **Tests**
* Added and strengthened tests for config authoring, rendering, CLI
behavior, and emulator flows
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-04-06 18:31:55 +00:00

50 lines
1.1 KiB
TypeScript

import { expect, it } from "vitest";
import { typeAssertExtends } from "./utils/types";
import { defineStackConfig, type StackConfig } from "./config-authoring";
const validConfig = defineStackConfig({
payments: {
items: {
todos: {
displayName: "Todo Slots",
customerType: "user",
},
},
},
});
typeAssertExtends<typeof validConfig, StackConfig>()();
it("returns its input unchanged", () => {
expect(defineStackConfig(validConfig)).toBe(validConfig);
});
defineStackConfig({
// @ts-expect-error Top-level dot notation should not be accepted in typed config files.
"payments.items": {
todos: {
displayName: "Todo Slots",
customerType: "user",
},
},
});
defineStackConfig({
payments: {
// @ts-expect-error Unknown keys should not be accepted in typed config files.
missingField: true,
},
});
defineStackConfig({
payments: {
items: {
todos: {
displayName: "Todo Slots",
// @ts-expect-error Invalid enum values should fail type-checking.
customerType: "workspace",
},
},
},
});