@carecard/validate 3.17.0 → 3.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/.agents/skills/carecard-workspace-standards/SKILL.md +49 -20
  2. package/.agents/skills/github-pr-create-update/SKILL.md +22 -1
  3. package/.agents/skills/github-pr-merge-cleanup/SKILL.md +22 -1
  4. package/.agents/skills/logged-in-user-profile-page/SKILL.md +22 -1
  5. package/.agents/skills/pkg-publish/SKILL.md +22 -1
  6. package/.agents/skills/pkg-validate-coding-standards-and-best-practices/SKILL.md +47 -9
  7. package/.agents/skills/pkg-validate-validation-library/SKILL.md +45 -14
  8. package/.agents/skills/software-design-patterns-and-clean-code/SKILL.md +23 -3
  9. package/.codex/AGENTS.md +41 -10
  10. package/.github/workflows/auto-draft-pr.yml +173 -151
  11. package/.github/workflows/ci.yml +35 -32
  12. package/.husky/pre-commit +4 -4
  13. package/.prettierrc.js +10 -9
  14. package/AGENTS.md +19 -0
  15. package/eslint.config.mjs +60 -8
  16. package/index.d.ts +108 -107
  17. package/index.js +6 -6
  18. package/lib/validate.js +230 -157
  19. package/lib/validateNewUserRoleRequest.js +68 -60
  20. package/lib/validateProperties.js +326 -326
  21. package/lib/validateWhitelistProperties.js +182 -142
  22. package/lint-staged.config.mjs +36 -0
  23. package/package.json +66 -60
  24. package/readme.md +22 -1
  25. package/scripts/canonicalTestCommand.test.mjs +32 -0
  26. package/scripts/packageTaskRunner.audit.mjs +37 -0
  27. package/scripts/packageTaskRunner.test.mjs +64 -0
  28. package/scripts/runPackageTask.mjs +135 -0
  29. package/scripts/testOrder/randomizeTestOrder.cjs +35 -25
  30. package/scripts/testOrder/randomizeTestOrder.test.mjs +19 -19
  31. package/scripts/testOrder/testOrderPolicy.audit.mjs +54 -0
  32. package/scripts/testParallel/parallelTestPolicy.audit.mjs +63 -0
  33. package/scripts/testParallel/runIndexedMochaTests.cjs +45 -43
  34. package/scripts/testParallel/runIndexedMochaTests.test.mjs +13 -7
  35. package/scripts/testOrder/testOrderPolicy.test.mjs +0 -48
  36. package/scripts/testParallel/parallelTestPolicy.test.mjs +0 -39
@@ -15,10 +15,13 @@ Non-negotiable test order invariance rule: Every test must pass independently of
15
15
 
16
16
  Non-negotiable parallel test execution rule: Run independent test files in parallel with repository-native worker support wherever resource isolation makes parallel execution safe. Tests that share a mutable database, application server, browser state, filesystem fixture, port, or cluster resource must remain in an explicitly isolated serial group until every worker owns a separate resource. Parallel execution must preserve ordinary test selection and must never use randomized ordering, retries, locks, or error suppression to conceal coupling.
17
17
 
18
- Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, add or update the relevant validation check before changing the prose.
18
+ Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, run the relevant focused non-test
19
+ validation before changing the prose; do not add automated tests that inspect
20
+ prose, files, or repository structure.
19
21
 
20
- This requirement is non-negotiable and may be overridden only with the user's
21
- explicit, direct approval.
22
+ The TDD and validation requirements are non-negotiable and cannot be
23
+ overridden. The separate pre-existing-test protection still requires the
24
+ user's fresh, explicit permission for each exact proposed test modification.
22
25
 
23
26
  A pre-existing test—defined as any test present before work on the current task
24
27
  begins—must not be deleted, disabled, skipped, weakened, excluded from execution,
@@ -30,6 +33,11 @@ precise proposed modification, provide detailed technical justification, and
30
33
  explain all known or reasonably foreseeable regression risks. Until approval is
31
34
  granted, leave every pre-existing test unchanged.
32
35
 
36
+ An implementation-detail test remains invalid under the authoritative TDD and
37
+ validation policy. Identify the exact test and obtain the user's explicit
38
+ approval before rewriting or removing it. Until approval is granted, leave the
39
+ test unchanged and report the blocked correction.
40
+
33
41
  Non-negotiable repository isolation rule: Every repository must run its Husky hooks and tests using only files, code, fixtures, dependencies, and services contained within that repository. Tests and Husky scripts must not import, require, read, execute, or otherwise depend on sibling repositories or paths outside the repository root. app-e2e-tests is the only exception because cross-repository end-to-end testing is its explicit responsibility.
34
42
 
35
43
  Non-negotiable error and warning rule: Never suppress, silence, hide, downgrade, filter, ignore, skip, or bypass errors or warnings from code, tests, tools, compilers, linters, or validation. Fix the root cause, then rerun the affected check and require a clean result. Expected error-path tests may assert errors, but must not conceal unexpected failures.
@@ -70,8 +78,10 @@ Use before modifying, testing, reviewing, or debugging any CareCard workspace re
70
78
 
71
79
  ## Testing Expectations
72
80
 
73
- - Write or update package tests before behavior or public API changes.
74
- - Include type/export compatibility tests where the package already has them.
81
+ - Write a new failing consumer-facing test through the supported package root
82
+ before behavior or public API changes. Modify a pre-existing test only after
83
+ the user grants fresh, explicit permission for that exact change.
84
+ - Include consumer-facing runtime and compilation tests through the supported package root. Exercise public behavior and realistic type usage without inspecting export objects, source files, or module layout.
75
85
  - Run package test, lint, type, and Husky validation commands required by the changed area.
76
86
 
77
87
  ## Safety Constraints
@@ -106,9 +116,10 @@ config.
106
116
  - Follow the owner's coding style, naming conventions, and project structure.
107
117
  - Put code, tests, docs, services, validation, transforms, components, and
108
118
  helpers where the current repository expects them.
109
- - Use Test-Driven Development for behavior changes: write or update focused
110
- tests first, verify they fail for the missing behavior when practical, then
111
- implement.
119
+ - Use Test-Driven Development for behavior changes: write a focused
120
+ functional test first or, after fresh permission for the exact change,
121
+ update a pre-existing test. Run the selected test, confirm it fails for the
122
+ missing behavior, then implement.
112
123
  - Never suppress errors, TypeScript errors, linter warnings, authorization
113
124
  failures, RLS failures, build failures, hydration issues, or failing tests.
114
125
  Do not add `eslint-disable`, `@ts-ignore`, broad catches, empty catches, or
@@ -309,10 +320,11 @@ existing TypeScript style.
309
320
  ## Tests
310
321
 
311
322
  - Testing is mandatory before finalizing code changes.
312
- - Code coverage percentage must not decrease from the previous commit; it can
313
- stay the same or increase. When coverage tooling exists, compare against the
314
- previous commit or recorded baseline, add tests to maintain or improve
315
- coverage, and never reduce coverage thresholds to pass checks.
323
+ - Use coverage reports only as diagnostics for potentially untested observable
324
+ behavior. Percentages for lines, branches, functions, and statements are not
325
+ functional evidence and must not determine test assertions. Never add
326
+ implementation-detail tests to preserve a metric or lower thresholds to hide
327
+ a failing check; report any conflict with the behavior-only policy.
316
328
  - Keep tests readable and domain-specific.
317
329
  - Tests must cover desired or happy paths and prevention or rejection of
318
330
  undesired behavior.
@@ -324,14 +336,14 @@ existing TypeScript style.
324
336
  Selenium for end-to-end flows.
325
337
  - For database tests, use existing seed, migration, rollback, and cleanup
326
338
  patterns.
327
- - In database `rls_logic.test.js` files, assert RLS logic only by calling
328
- `carecard.can_access_row(...)` and checking the intended boolean. Put table
329
- CRUD and lower RLS helper checks in query/enforcement tests.
339
+ - Test row-level security through app-equivalent SQL operations under the
340
+ intended caller context. Assert returned rows, successful writes, and
341
+ authorization denials without calling internal RLS helpers or inspecting SQL
342
+ text.
330
343
  - Add tests for API success responses, validation errors, auth/authz errors,
331
344
  JWT errors, not-found/conflict cases, and unexpected error handling when
332
345
  those paths change.
333
- - For frontend changes, test validation, transforms, query/mutation wrappers,
334
- components, and user-visible flows at the narrowest practical level first.
346
+ - For frontend changes, test rendered UI, public HTTP or network outcomes, navigation, accessibility, and user-visible flows at the narrowest practical level first. Use focused non-test dependency checks for validation, transform, query, mutation, hook, and module organization.
335
347
  - If a test or repository check fails, fix the issue and rerun the failing
336
348
  command. Only finalize with failing checks when the failure is unrelated or
337
349
  blocked by environment constraints, and document that explicitly.
@@ -370,9 +382,7 @@ Dashboard service and test conventions:
370
382
  - Profile, settings, notifications, institutions, and user authorization UI
371
383
  prefer service snackbar helpers for user-friendly fallback errors, technical
372
384
  error filtering, mutation result handling, and duplicate error suppression.
373
- - `tests/app/dashboard/profile/page.test.tsx` keeps dynamic profile children
374
- inert in the shell-level page test to avoid async imports resolving after
375
- Vitest tears down jsdom in CI.
385
+ - Profile page tests assert visible loading, navigation, form, and error behavior through the rendered route. They must not depend on dynamic-import structure or a specific mocking strategy.
376
386
 
377
387
  ## Public Website Frontends
378
388
 
@@ -432,3 +442,22 @@ the authenticated dashboard.
432
442
  intact unless a task explicitly changes them.
433
443
  - Document remaining security concerns that require product, infrastructure, or
434
444
  deployment decisions.
445
+
446
+ ## TDD And Validation
447
+
448
+ Test Driven Development is a non-negotiable requirement.
449
+
450
+ The sole purpose of automated tests is to verify observable functionality and externally visible behavior.
451
+ Tests must validate what the system does through its public interfaces and expected outcomes.
452
+
453
+ Tests must not assert, inspect, or depend on implementation details, including but not limited to:
454
+
455
+ - The existence of specific lines of code, statements, functions, classes, files, or modules.
456
+ - Specific algorithms, control flow, variable names, method calls, code snippets, or internal implementation choices.
457
+ - Any internal structure that can change without changing externally observable behavior.
458
+
459
+ A correct implementation may be completely rewritten or refactored without requiring changes to functional tests, provided its externally observable behavior remains unchanged.
460
+
461
+ Any test that fails solely because the implementation changed while the externally observable behavior remained correct is incorrectly designed and must be rewritten or removed.
462
+
463
+ This requirement is mandatory for all new tests and must be applied whenever existing tests are modified.
@@ -7,7 +7,9 @@ Non-negotiable root-cause solution rule: Always identify and solve the verified
7
7
 
8
8
  # Pull Request Create
9
9
 
10
- Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, add or update the relevant validation check before changing the prose.
10
+ Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, run the relevant focused non-test
11
+ validation before changing the prose; do not add automated tests that inspect
12
+ prose, files, or repository structure.
11
13
 
12
14
  Non-negotiable repository isolation rule: Every repository must run its Husky hooks and tests using only files, code, fixtures, dependencies, and services contained within that repository. Tests and Husky scripts must not import, require, read, execute, or otherwise depend on sibling repositories or paths outside the repository root. app-e2e-tests is the only exception because cross-repository end-to-end testing is its explicit responsibility.
13
15
 
@@ -181,3 +183,22 @@ Do not continue automatically when:
181
183
  10. Final response should include the PR URL, selected base branch, whether a
182
184
  rebase was performed, whether an existing PR was reused or marked ready,
183
185
  and any validation that could not be run.
186
+
187
+ ## TDD And Validation
188
+
189
+ Test Driven Development is a non-negotiable requirement.
190
+
191
+ The sole purpose of automated tests is to verify observable functionality and externally visible behavior.
192
+ Tests must validate what the system does through its public interfaces and expected outcomes.
193
+
194
+ Tests must not assert, inspect, or depend on implementation details, including but not limited to:
195
+
196
+ - The existence of specific lines of code, statements, functions, classes, files, or modules.
197
+ - Specific algorithms, control flow, variable names, method calls, code snippets, or internal implementation choices.
198
+ - Any internal structure that can change without changing externally observable behavior.
199
+
200
+ A correct implementation may be completely rewritten or refactored without requiring changes to functional tests, provided its externally observable behavior remains unchanged.
201
+
202
+ Any test that fails solely because the implementation changed while the externally observable behavior remained correct is incorrectly designed and must be rewritten or removed.
203
+
204
+ This requirement is mandatory for all new tests and must be applied whenever existing tests are modified.
@@ -7,7 +7,9 @@ Non-negotiable root-cause solution rule: Always identify and solve the verified
7
7
 
8
8
  # Pull Request Merge Close
9
9
 
10
- Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, add or update the relevant validation check before changing the prose.
10
+ Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, run the relevant focused non-test
11
+ validation before changing the prose; do not add automated tests that inspect
12
+ prose, files, or repository structure.
11
13
 
12
14
  Non-negotiable repository isolation rule: Every repository must run its Husky hooks and tests using only files, code, fixtures, dependencies, and services contained within that repository. Tests and Husky scripts must not import, require, read, execute, or otherwise depend on sibling repositories or paths outside the repository root. app-e2e-tests is the only exception because cross-repository end-to-end testing is its explicit responsibility.
13
15
 
@@ -233,3 +235,22 @@ completion.
233
235
  cleanup commit was added, whether the remote target branch was deleted or
234
236
  protected, whether the local target branch was deleted, and whether local
235
237
  base branch is up to date.
238
+
239
+ ## TDD And Validation
240
+
241
+ Test Driven Development is a non-negotiable requirement.
242
+
243
+ The sole purpose of automated tests is to verify observable functionality and externally visible behavior.
244
+ Tests must validate what the system does through its public interfaces and expected outcomes.
245
+
246
+ Tests must not assert, inspect, or depend on implementation details, including but not limited to:
247
+
248
+ - The existence of specific lines of code, statements, functions, classes, files, or modules.
249
+ - Specific algorithms, control flow, variable names, method calls, code snippets, or internal implementation choices.
250
+ - Any internal structure that can change without changing externally observable behavior.
251
+
252
+ A correct implementation may be completely rewritten or refactored without requiring changes to functional tests, provided its externally observable behavior remains unchanged.
253
+
254
+ Any test that fails solely because the implementation changed while the externally observable behavior remained correct is incorrectly designed and must be rewritten or removed.
255
+
256
+ This requirement is mandatory for all new tests and must be applied whenever existing tests are modified.
@@ -7,7 +7,9 @@ Non-negotiable root-cause solution rule: Always identify and solve the verified
7
7
 
8
8
  # Logged-In User Profile Page
9
9
 
10
- Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, add or update the relevant validation check before changing the prose.
10
+ Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, run the relevant focused non-test
11
+ validation before changing the prose; do not add automated tests that inspect
12
+ prose, files, or repository structure.
11
13
 
12
14
  Non-negotiable repository isolation rule: Every repository must run its Husky hooks and tests using only files, code, fixtures, dependencies, and services contained within that repository. Tests and Husky scripts must not import, require, read, execute, or otherwise depend on sibling repositories or paths outside the repository root. app-e2e-tests is the only exception because cross-repository end-to-end testing is its explicit responsibility.
13
15
 
@@ -41,3 +43,22 @@ Relevant profile/settings fields:
41
43
  - Run focused Mocha tests for the changed validator keys.
42
44
  - Run `npm run test:types` when public exports or declarations are affected.
43
45
  - Run `npm run test:All` for validator contract changes before finalizing.
46
+
47
+ ## TDD And Validation
48
+
49
+ Test Driven Development is a non-negotiable requirement.
50
+
51
+ The sole purpose of automated tests is to verify observable functionality and externally visible behavior.
52
+ Tests must validate what the system does through its public interfaces and expected outcomes.
53
+
54
+ Tests must not assert, inspect, or depend on implementation details, including but not limited to:
55
+
56
+ - The existence of specific lines of code, statements, functions, classes, files, or modules.
57
+ - Specific algorithms, control flow, variable names, method calls, code snippets, or internal implementation choices.
58
+ - Any internal structure that can change without changing externally observable behavior.
59
+
60
+ A correct implementation may be completely rewritten or refactored without requiring changes to functional tests, provided its externally observable behavior remains unchanged.
61
+
62
+ Any test that fails solely because the implementation changed while the externally observable behavior remained correct is incorrectly designed and must be rewritten or removed.
63
+
64
+ This requirement is mandatory for all new tests and must be applied whenever existing tests are modified.
@@ -9,7 +9,9 @@ Non-negotiable root-cause solution rule: Always identify and solve the verified
9
9
 
10
10
  Non-negotiable test order invariance rule: Every test must pass independently of which tests run before or after it, and the suite must pass in every execution order. Each test must establish the state it needs, isolate mutable state, and clean up state it owns; it must never rely on another test's setup, mutations, or cleanup. Default test, CI, and Husky commands must use the test framework's ordinary ordering and must not force randomized ordering. Random-order execution is an explicit diagnostic only, and every failure it exposes must be fixed at the root cause.
11
11
 
12
- Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, add or update the relevant validation check before changing the prose.
12
+ Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, run the relevant focused non-test
13
+ validation before changing the prose; do not add automated tests that inspect
14
+ prose, files, or repository structure.
13
15
 
14
16
  Non-negotiable repository isolation rule: Every repository must run its Husky hooks and tests using only files, code, fixtures, dependencies, and services contained within that repository. Tests and Husky scripts must not import, require, read, execute, or otherwise depend on sibling repositories or paths outside the repository root. app-e2e-tests is the only exception because cross-repository end-to-end testing is its explicit responsibility.
15
17
 
@@ -123,3 +125,22 @@ For each changed repository:
123
125
  Finish by verifying that all five packages are published at the same target
124
126
  version and every declared `@carecard/*` dependency in `pkg-*`, `ms-*`, and
125
127
  `app-dashboard` is pinned to that version.
128
+
129
+ ## TDD And Validation
130
+
131
+ Test Driven Development is a non-negotiable requirement.
132
+
133
+ The sole purpose of automated tests is to verify observable functionality and externally visible behavior.
134
+ Tests must validate what the system does through its public interfaces and expected outcomes.
135
+
136
+ Tests must not assert, inspect, or depend on implementation details, including but not limited to:
137
+
138
+ - The existence of specific lines of code, statements, functions, classes, files, or modules.
139
+ - Specific algorithms, control flow, variable names, method calls, code snippets, or internal implementation choices.
140
+ - Any internal structure that can change without changing externally observable behavior.
141
+
142
+ A correct implementation may be completely rewritten or refactored without requiring changes to functional tests, provided its externally observable behavior remains unchanged.
143
+
144
+ Any test that fails solely because the implementation changed while the externally observable behavior remained correct is incorrectly designed and must be rewritten or removed.
145
+
146
+ This requirement is mandatory for all new tests and must be applied whenever existing tests are modified.
@@ -5,6 +5,19 @@ description: 'Mandatory for every pkg-validate task, including analysis, clarifi
5
5
 
6
6
  # Pkg Validate Coding Standards And Best Practices
7
7
 
8
+ ## JavaScript And TypeScript Style Contract
9
+
10
+ - Require braces around every optional control-flow body through ESLint core
11
+ `curly: ['error', 'all']`. Single-expression arrow functions may remain
12
+ expression-bodied.
13
+ - Require semicolons on every applicable statement through Prettier's
14
+ `semi: true` option. Do not add a second semicolon linter.
15
+ - Keep the shared Prettier baseline and lint-staged command order consistent
16
+ across CareCard repositories: run ESLint fixes before Prettier writes.
17
+ - Use `lint`, `lint:fix`, `format`, `format:check`, and `lint-staged` as the
18
+ direct script names. Whole-repository lint and formatting checks must fail on
19
+ warnings or style drift.
20
+
8
21
  Non-negotiable root-cause solution rule: Always identify and solve the verified
9
22
  root cause, use the stronger solution, and deliver a correct, durable,
10
23
  production-quality result. Never treat a temporary workaround, resource
@@ -65,9 +78,11 @@ completion rules below without weakening those companion skills.
65
78
 
66
79
  - Treat every workspace repository as independent and validate it from its own
67
80
  root.
68
- - Update every skill, document, source, runtime test, type test, export,
69
- declaration, consumer, and package version genuinely required for a coherent
70
- task.
81
+ - Update every skill, document, source, export, declaration, consumer, and
82
+ package version genuinely required for a coherent task, and add every new
83
+ consumer-facing runtime or type test the behavior requires. Modify a
84
+ pre-existing test only after the user grants fresh, explicit permission for
85
+ that exact change.
71
86
  - Do not broaden the task into unrelated cleanup.
72
87
  - Preserve CommonJS, predicate, sanitization, whitelist, declaration, naming,
73
88
  and test conventions unless the task explicitly replaces them.
@@ -102,17 +117,21 @@ overloads, duplicate exports, dual validation paths, transitional names, or
102
117
  fallback behavior solely to preserve the superseded contract.
103
118
 
104
119
  Delete obsolete functions and exports after all intended consumers have
105
- migrated and repository-native search, runtime tests, type tests, and coverage
106
- prove them unused. This does not authorize unrelated API removal. If an
107
- existing published or security contract requires compatibility and the request
108
- does not clearly supersede it, explain the conflict and ask first.
120
+ migrated and repository-native search proves them unused. Runtime and type
121
+ tests verify the supported public behavior and consumer contract without
122
+ inspecting implementation structure; coverage measures exercised observable
123
+ behavior. This does not authorize unrelated API removal. If an existing
124
+ published or security contract requires compatibility and the request does not
125
+ clearly supersede it, explain the conflict and ask first.
109
126
 
110
127
  ## TDD And Root-Cause Gate
111
128
 
112
129
  Follow `$carecard-workspace-standards` and
113
130
  `$pkg-validate-validation-library` for the complete failing-test-first,
114
- root-cause, and 100-percent-coverage workflow. Documentation and skill changes
115
- require a focused structural validation before prose changes. Do not accept
131
+ root-cause, behavior-focused validation, and diagnostic-coverage workflow.
132
+ Coverage never authorizes implementation-detail tests. Documentation and skill changes require focused non-test validation before
133
+ prose changes; do not add automated tests that inspect prose, files, or
134
+ repository structure. Do not accept
116
135
  retries, suppressed diagnostics, weakened types, reduced coverage, disabled
117
136
  tests, forced success, compatibility patches, or symptom-only workarounds as
118
137
  completion.
@@ -163,3 +182,22 @@ them unused and replaced.
163
182
  5. Fix every in-scope failure at its root cause and rerun the exact command.
164
183
  6. Report exact commands, results, limitations, and remaining risk.
165
184
  7. Do not perform remote Git or GitHub operations unless explicitly requested.
185
+
186
+ ## TDD And Validation
187
+
188
+ Test Driven Development is a non-negotiable requirement.
189
+
190
+ The sole purpose of automated tests is to verify observable functionality and externally visible behavior.
191
+ Tests must validate what the system does through its public interfaces and expected outcomes.
192
+
193
+ Tests must not assert, inspect, or depend on implementation details, including but not limited to:
194
+
195
+ - The existence of specific lines of code, statements, functions, classes, files, or modules.
196
+ - Specific algorithms, control flow, variable names, method calls, code snippets, or internal implementation choices.
197
+ - Any internal structure that can change without changing externally observable behavior.
198
+
199
+ A correct implementation may be completely rewritten or refactored without requiring changes to functional tests, provided its externally observable behavior remains unchanged.
200
+
201
+ Any test that fails solely because the implementation changed while the externally observable behavior remained correct is incorrectly designed and must be rewritten or removed.
202
+
203
+ This requirement is mandatory for all new tests and must be applied whenever existing tests are modified.
@@ -7,7 +7,9 @@ Non-negotiable root-cause solution rule: Always identify and solve the verified
7
7
 
8
8
  # Package Validate
9
9
 
10
- Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, add or update the relevant validation check before changing the prose.
10
+ Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, run the relevant focused non-test
11
+ validation before changing the prose; do not add automated tests that inspect
12
+ prose, files, or repository structure.
11
13
 
12
14
  Non-negotiable repository isolation rule: Every repository must run its Husky hooks and tests using only files, code, fixtures, dependencies, and services contained within that repository. Tests and Husky scripts must not import, require, read, execute, or otherwise depend on sibling repositories or paths outside the repository root. app-e2e-tests is the only exception because cross-repository end-to-end testing is its explicit responsibility.
13
15
 
@@ -49,8 +51,10 @@ CareCard validation package for deterministic validators, sanitization, whitelis
49
51
 
50
52
  ## Testing Expectations
51
53
 
52
- - Write or update package tests before behavior or public API changes.
53
- - Include type/export compatibility tests where the package already has them.
54
+ - Write a new failing consumer-facing test through the supported package root
55
+ before behavior or public API changes. Modify a pre-existing test only after
56
+ the user grants fresh, explicit permission for that exact change.
57
+ - Include consumer-facing runtime and compilation tests through the supported package root. Exercise public behavior and realistic type usage without inspecting export objects, source files, or module layout.
54
58
  - Run package test, lint, type, and Husky validation commands required by the changed area.
55
59
 
56
60
  ## Safety Constraints
@@ -77,8 +81,10 @@ depend on those folders being present.
77
81
  option, result, generic, or `unknown` types with narrowing.
78
82
  - Follow this repository's coding style, naming conventions, and CommonJS
79
83
  project structure.
80
- - Use Test-Driven Development: add or update relevant Mocha or type tests before
81
- changing behavior.
84
+ - Use Test-Driven Development: add a new failing consumer-facing Mocha or type
85
+ test through the supported package root before changing behavior. Modify a
86
+ pre-existing test only after the user grants fresh, explicit permission for
87
+ that exact change.
82
88
  - Never suppress errors, linter warnings, TypeScript errors, or failing tests.
83
89
  Handle the underlying issue.
84
90
  - Do not add dependencies unless absolutely needed. Ask for confirmation first
@@ -125,22 +131,28 @@ depend on those folders being present.
125
131
  validators, and failure-message helpers explicitly in `index.d.ts`.
126
132
  - When existing declarations are too loose, improve them with specific types as
127
133
  part of the touched change instead of adding new loose types.
128
- - Update `test/types.test.ts` whenever public types, exports, options, return
129
- values, or validators change.
134
+ - When public types, options, return values, or validator behavior changes,
135
+ compile realistic consumer usage through the supported package root. Do not
136
+ assert that named exports or declaration nodes exist.
130
137
  - Keep runtime exports, README examples, and type declarations in sync.
131
138
  - Preserve validation behavior for invalid, missing, extra, and valid fields.
132
139
 
133
140
  ## Tests And Coverage
134
141
 
135
142
  - Use Mocha for runtime tests under `test`.
136
- - Use `test/types.test.ts` for TypeScript declaration coverage through
137
- `npm run test:types`.
138
- - Add focused tests for valid input, invalid input, missing fields, optional
139
- fields, array handling, nested paths, casing conversion, flattening, and error
140
- messages when those areas change.
143
+ - Use `npm run test:types` to compile realistic consumer code through the
144
+ supported package root and verify externally visible declaration behavior.
145
+ - Add new focused consumer-facing tests through the supported package root for
146
+ valid input, invalid input, missing fields, optional fields, array handling,
147
+ nested paths, casing conversion, flattening, and error messages when those
148
+ areas change. Modify a pre-existing test only after the user grants fresh,
149
+ explicit permission for that exact change.
141
150
  - Keep tests deterministic and avoid real external services.
142
- - This package enforces 100% coverage for branches, functions, lines, and
143
- statements through `nyc`; do not reduce thresholds.
151
+ - The existing `nyc` command reports branches, functions, lines, and
152
+ statements. Treat those percentages only as diagnostics, never as
153
+ functional evidence or a reason to assert implementation details. Do not
154
+ add tests solely to satisfy the metric or lower thresholds to hide a
155
+ failure; report any threshold conflict with the behavior-only policy.
144
156
 
145
157
  ## Legacy Junie Source Notes
146
158
 
@@ -228,3 +240,22 @@ immediately when no helper remains, allow only a bounded 250 ms settlement
228
240
  window for already-stopping helpers, fail persistent descendants, preserve
229
241
  failures and output, use exit code `124` only for a real outer deadline, and
230
242
  remain a final guard rather than a substitute for explicit cleanup.
243
+
244
+ ## TDD And Validation
245
+
246
+ Test Driven Development is a non-negotiable requirement.
247
+
248
+ The sole purpose of automated tests is to verify observable functionality and externally visible behavior.
249
+ Tests must validate what the system does through its public interfaces and expected outcomes.
250
+
251
+ Tests must not assert, inspect, or depend on implementation details, including but not limited to:
252
+
253
+ - The existence of specific lines of code, statements, functions, classes, files, or modules.
254
+ - Specific algorithms, control flow, variable names, method calls, code snippets, or internal implementation choices.
255
+ - Any internal structure that can change without changing externally observable behavior.
256
+
257
+ A correct implementation may be completely rewritten or refactored without requiring changes to functional tests, provided its externally observable behavior remains unchanged.
258
+
259
+ Any test that fails solely because the implementation changed while the externally observable behavior remained correct is incorrectly designed and must be rewritten or removed.
260
+
261
+ This requirement is mandatory for all new tests and must be applied whenever existing tests are modified.
@@ -7,7 +7,9 @@ Non-negotiable root-cause solution rule: Always identify and solve the verified
7
7
 
8
8
  # Software Design Patterns And Clean Code
9
9
 
10
- Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, add or update the relevant validation check before changing the prose.
10
+ Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, run the relevant focused non-test
11
+ validation before changing the prose; do not add automated tests that inspect
12
+ prose, files, or repository structure.
11
13
 
12
14
  Non-negotiable repository isolation rule: Every repository must run its Husky hooks and tests using only files, code, fixtures, dependencies, and services contained within that repository. Tests and Husky scripts must not import, require, read, execute, or otherwise depend on sibling repositories or paths outside the repository root. app-e2e-tests is the only exception because cross-repository end-to-end testing is its explicit responsibility.
13
15
 
@@ -41,8 +43,7 @@ validation commands, and API contracts.
41
43
  - Keep side effects minimal, localized, and easy to identify.
42
44
  - Use explicit error handling. Do not swallow failures or hide actionable
43
45
  error context.
44
- - Design code so behavior can be tested through focused unit, integration, or
45
- service tests without fragile setup.
46
+ - Design code so behavior can be tested through focused public interfaces, integration boundaries, and observable outcomes without fragile setup or internal-module assertions.
46
47
  - Avoid unnecessary dependencies. Use existing language, framework, and local
47
48
  helper capabilities before adding packages.
48
49
 
@@ -83,3 +84,22 @@ async function loadProfile(...) { ... }
83
84
  only have one trivial implementation unless they clarify a boundary.
84
85
  - Preserve the repository's existing style, naming, module system, and testing
85
86
  approach.
87
+
88
+ ## TDD And Validation
89
+
90
+ Test Driven Development is a non-negotiable requirement.
91
+
92
+ The sole purpose of automated tests is to verify observable functionality and externally visible behavior.
93
+ Tests must validate what the system does through its public interfaces and expected outcomes.
94
+
95
+ Tests must not assert, inspect, or depend on implementation details, including but not limited to:
96
+
97
+ - The existence of specific lines of code, statements, functions, classes, files, or modules.
98
+ - Specific algorithms, control flow, variable names, method calls, code snippets, or internal implementation choices.
99
+ - Any internal structure that can change without changing externally observable behavior.
100
+
101
+ A correct implementation may be completely rewritten or refactored without requiring changes to functional tests, provided its externally observable behavior remains unchanged.
102
+
103
+ Any test that fails solely because the implementation changed while the externally observable behavior remained correct is incorrectly designed and must be rewritten or removed.
104
+
105
+ This requirement is mandatory for all new tests and must be applied whenever existing tests are modified.
package/.codex/AGENTS.md CHANGED
@@ -16,8 +16,9 @@ Non-negotiable repository isolation rule: Every repository must run its Husky ho
16
16
 
17
17
  Non-negotiable error and warning rule: Never suppress, silence, hide, downgrade, filter, ignore, skip, or bypass errors or warnings from code, tests, tools, compilers, linters, or validation. Fix the root cause, then rerun the affected check and require a clean result. Expected error-path tests may assert errors, but must not conceal unexpected failures.
18
18
 
19
- This requirement is non-negotiable and may be overridden only with the user's
20
- explicit, direct approval.
19
+ The TDD and validation requirements are non-negotiable and cannot be
20
+ overridden. The separate pre-existing-test protection still requires the
21
+ user's fresh, explicit permission for each exact proposed test modification.
21
22
 
22
23
  A pre-existing test—defined as any test present before work on the current task
23
24
  begins—must not be deleted, disabled, skipped, weakened, excluded from execution,
@@ -29,6 +30,11 @@ precise proposed modification, provide detailed technical justification, and
29
30
  explain all known or reasonably foreseeable regression risks. Until approval is
30
31
  granted, leave every pre-existing test unchanged.
31
32
 
33
+ An implementation-detail test remains invalid under the authoritative TDD and
34
+ validation policy. Identify the exact test and obtain the user's explicit
35
+ approval before rewriting or removing it. Until approval is granted, leave the
36
+ test unchanged and report the blocked correction.
37
+
32
38
  These instructions apply to the `pkg-validate` repository. This file is self-contained:
33
39
  it includes the workspace-level instructions that were previously read from
34
40
  `/Users/pankajpriscilla/SO_CareCardCa/.codex/AGENTS.md`, followed by
@@ -45,7 +51,7 @@ These instructions apply to the whole workspace. The workspace is a collection o
45
51
  - **Always follow the owner's coding style.** Preserve the existing style in the file and repository you are editing.
46
52
  - **Always follow the owner's naming conventions.** Use meaningful function, variable, file, test, and type names that match the surrounding code.
47
53
  - **Always follow the existing project structure.** Put code, tests, docs, services, validation, transforms, components, and helpers where the current repository already expects them.
48
- - **Always use Test-Driven Development.** Write or update focused tests first, verify they fail for the missing behavior when practical, then implement the code.
54
+ - **Always use Test-Driven Development.** Write a focused functional test first or, after fresh permission for the exact change, update a pre-existing test. Run the selected test, confirm it fails for the missing behavior, then implement the code.
49
55
  - **Never suppress errors, TypeScript errors, linter warnings, or failing tests.** Do not add `eslint-disable`, `@ts-ignore`, broad catches, empty catches, or other suppression. Fix the root cause.
50
56
  - **Do not add new dependencies unless they are clearly necessary.** If a dependency might be needed, stop and ask for confirmation first, with a clear reason, tradeoff, and why existing code cannot reasonably solve it.
51
57
  - **Before finalizing any response for a repository, run every script in that repository's `.husky` directory.** Do not bypass hooks. If a `.husky` script fails, fix the underlying issue and rerun it. If it cannot run because of environment constraints, report the exact script and reason.
@@ -57,7 +63,10 @@ These instructions apply to the whole workspace. The workspace is a collection o
57
63
  - Explain architectural tradeoffs before major changes, especially changes that affect shared packages, API contracts, security, persistence, authentication, or frontend/backend boundaries.
58
64
  - Favor readable, maintainable code over short clever code.
59
65
  - Preserve the existing project style, file structure, naming style, module system, and test framework.
60
- - Use Test-Driven Development: write or update focused tests first, then implement the code.
66
+ - Use Test-Driven Development: write a new focused functional test through a
67
+ public interface first, confirm the intended behavioral failure, then
68
+ implement the code. Modify a pre-existing test only after the user grants
69
+ fresh, explicit permission for that exact change.
61
70
  - Use meaningful function and variable names. Names should expose intent and domain behavior.
62
71
  - Use specific types everywhere. Do not use `any`.
63
72
  - Keep changes scoped and easy to review. Avoid unrelated formatting churn or opportunistic refactors.
@@ -119,9 +128,9 @@ The `pkg-*` directories are reusable CareCard packages. Shared API response, err
119
128
 
120
129
  ### Tests
121
130
 
122
- - Write or update tests before implementation whenever changing behavior.
131
+ - Write a focused functional test before implementation whenever behavior changes. Modify a pre-existing test only after the user grants fresh, explicit permission for that exact change.
123
132
  - Testing is mandatory before finalizing code changes. Do not stop after implementation if tests, `.junie`, or `.husky` checks remain unrun.
124
- - Code coverage must never be lower than the previous commit. When coverage tooling exists, compare against the previous commit or recorded baseline before finalizing, add tests to maintain or improve coverage, and never reduce coverage thresholds to make checks pass.
133
+ - Use coverage reports only as diagnostics for potentially untested observable behavior. Percentages for lines, branches, functions, and statements are not functional evidence and must not determine test assertions. Never add implementation-detail tests to preserve a metric or lower thresholds to hide a failing check; report any conflict with the behavior-only policy.
125
134
  - Keep tests readable and domain-specific. Prefer explicit helper names over generic test utilities that hide important behavior.
126
135
  - Use existing test frameworks and layouts:
127
136
  - JavaScript `api-*`: usually Mocha, Supertest, `test/index.test.js`, and Docker-backed Postgres scripts.
@@ -130,7 +139,7 @@ The `pkg-*` directories are reusable CareCard packages. Shared API response, err
130
139
  - `app-dashboard`: Vitest, React Testing Library, mock API tests, and Selenium for end-to-end flows.
131
140
  - For database tests, use existing seed, migration, rollback, and cleanup patterns. Keep tests isolated and make cleanup reliable even after failures.
132
141
  - Add tests for API success responses, validation errors, auth/authz errors, JWT errors, not-found/conflict cases, and unexpected error handling when those paths change.
133
- - For frontend changes, test validation, transforms, query/mutation wrappers, components, and user-visible flows at the narrowest practical level first.
142
+ - For frontend changes, test rendered UI, public HTTP or network outcomes, navigation, accessibility, and user-visible flows at the narrowest practical level first. Use focused non-test dependency checks for validation, transform, query, mutation, hook, and module organization.
134
143
  - If any test or repository check fails, fix the issue and rerun the failing command. Only finalize with failing checks when the failure is unrelated to the change or blocked by environment constraints, and document that explicitly.
135
144
 
136
145
  ### Dashboard Frontend
@@ -167,7 +176,10 @@ The `pkg-*` directories are reusable CareCard packages. Shared API response, err
167
176
 
168
177
  - Never use TypeScript type `any`. Use specific value, record, validator, option, result, generic, or `unknown` types with narrowing.
169
178
  - Always follow this repository's coding style, naming conventions, and CommonJS project structure.
170
- - Always use Test-Driven Development: add or update the relevant Mocha or type tests before changing behavior.
179
+ - Always use Test-Driven Development: add a new failing consumer-facing Mocha
180
+ or type test through the supported package root before changing behavior.
181
+ Modify a pre-existing test only after the user grants fresh, explicit
182
+ permission for that exact change.
171
183
  - Never suppress errors, linter warnings, TypeScript errors, or failing tests. Handle the underlying issue.
172
184
  - Do not add new dependencies unless they are absolutely needed. Ask for confirmation first with the reason and tradeoff.
173
185
  - Before finalizing work in this repository, run every script in `.husky/` and fix anything they report.
@@ -197,13 +209,32 @@ The `pkg-*` directories are reusable CareCard packages. Shared API response, err
197
209
 
198
210
  - Model input and output records, whitelist options, flattened output behavior, validators, and failure-message helpers explicitly in `index.d.ts`.
199
211
  - When existing declarations are too loose, improve them with specific types as part of the touched change instead of adding new loose types.
200
- - Update `test/types.test.ts` whenever public types, exports, options, return values, or validators change.
212
+ - When public types, options, return values, or validator behavior changes, compile realistic consumer usage through the supported package root. Do not assert that named exports or declaration nodes exist.
201
213
  - Keep runtime exports, README examples, and type declarations in sync.
202
214
 
203
215
  ### Tests
204
216
 
205
217
  - Use Mocha for runtime tests under `test/`.
206
- - Use `test/types.test.ts` for TypeScript declaration coverage through `npm run test:types`.
218
+ - Use `npm run test:types` to compile realistic consumer code through the supported package root and verify externally visible declaration behavior.
207
219
  - Add focused tests for valid input, invalid input, missing fields, optional fields, array handling, nested paths, casing conversion, flattening, and error messages when those areas change.
208
220
  - Keep tests deterministic and avoid relying on real external services.
209
221
  - Before pushing or finalizing, run `.husky/pre-commit`; it runs lint fixing, formatting, and `npm run test:All`.
222
+
223
+ ## TDD And Validation
224
+
225
+ Test Driven Development is a non-negotiable requirement.
226
+
227
+ The sole purpose of automated tests is to verify observable functionality and externally visible behavior.
228
+ Tests must validate what the system does through its public interfaces and expected outcomes.
229
+
230
+ Tests must not assert, inspect, or depend on implementation details, including but not limited to:
231
+
232
+ - The existence of specific lines of code, statements, functions, classes, files, or modules.
233
+ - Specific algorithms, control flow, variable names, method calls, code snippets, or internal implementation choices.
234
+ - Any internal structure that can change without changing externally observable behavior.
235
+
236
+ A correct implementation may be completely rewritten or refactored without requiring changes to functional tests, provided its externally observable behavior remains unchanged.
237
+
238
+ Any test that fails solely because the implementation changed while the externally observable behavior remained correct is incorrectly designed and must be rewritten or removed.
239
+
240
+ This requirement is mandatory for all new tests and must be applied whenever existing tests are modified.