feat(varlock): add code env scanner and audit command#569
feat(varlock): add code env scanner and audit command#569danish-fareed wants to merge 4 commits intodmno-dev:mainfrom
Conversation
|
|
thanks @danish-fareed, we'll have a look soon! |
commit: |
There was a problem hiding this comment.
Pull request overview
Adds a new codebase env-var scanner and an audit CLI command to compare env var usage in source code against keys declared in .env.schema, plus wiring the scanner into varlock init as a fallback schema scaffold source.
Changes:
- Introduces a multi-language env var reference scanner with ignored-directory support, masking, and bounded concurrency.
- Adds
varlock auditcommand + helper diffing logic, with tests and CLI wiring. - Updates
varlock initto optionally scaffold schema items from scanned code references when no example/sample env file is present.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/varlock/src/env-graph/test/resolvers.test.ts | Normalizes CRLF-sensitive string assertions in resolver tests. |
| packages/varlock/src/cli/helpers/test/env-var-scanner.test.ts | Adds focused tests for scanner detection + masking + ignored dirs behavior. |
| packages/varlock/src/cli/helpers/infer-schema.ts | Exports inferItemDecorators and makes valueStr optional for reuse in init scaffolding. |
| packages/varlock/src/cli/helpers/env-var-scanner.ts | New scanner implementation (multi-language regexes, masking, glob discovery, concurrency). |
| packages/varlock/src/cli/helpers/audit-diff.ts | Adds schema/code key diff helper used by audit command and tests. |
| packages/varlock/src/cli/commands/test/audit.command.test.ts | Adds tests for audit behavior and scan-root path handling. |
| packages/varlock/src/cli/commands/init.command.ts | Falls back to scanning code to inject new schema keys when no example env file exists. |
| packages/varlock/src/cli/commands/audit.command.ts | New varlock audit command implementation and output/exit-code behavior. |
| packages/varlock/src/cli/cli-executable.ts | Registers audit subcommand for the CLI executable. |
| packages/varlock-website/src/content/docs/reference/cli-commands.mdx | Documents the new varlock audit command and exit codes. |
|
A quick first pass and this is looking really good! Thanks so much for the contribution. Couple small things come to mind in terms of audit behaviour. If the user end up building auditing into their workflows, we may want a way for the user to mark certain vars as being acknowledged as not being detected. For example you may have some vars that ambiently affect other tools without necessarily appearing in code. Similarly we may want the user to be able to record paths/globs to ignore during an audit somehow within their schema (or some other config location) without having to pass them into the the audit command every time. |
Both of those are great points. Here's what I'm planning to implement using the existing decorator syntax: A new item-level New top-level Let me know if you'd prefer different naming or want the ignore paths to live somewhere other than the schema |
|
Probably keeping Maybe something like Then for the root ignore decorator, I would make it a function. Again include "audit" maybe Any other ideas come to mind? |
|
That makes perfect sense! Using a function for @auditIgnorePaths(glob1, glob2) is a great call so they merge correctly across imported files. And @auditIgnore is the perfect lightweight solution for specific items. |
Update audit to support root-level @auditIgnorePaths() merging and item-level @auditIgnore suppression with strict true checks. This keeps missing-in-schema reporting unchanged while preserving default scanner ignores and adding additive exclude coverage.
Switch masking to code-unit iteration to preserve index stability with astral characters and mask Go raw-string literals to avoid false positives in audit scans.
|
implemented your audit decorator suggestions and pushed updates. @auditIgnorePaths(...) now merges across files, @auditIgnore suppresses only unused warnings (strict true), missing-key behavior is unchanged, and all local checks are passing. Review thoroughly when you get time. |
|
Thanks for all this - will try to get it out sometime next week! |
Summary
varlock audit, with bounded concurrency and comment/string masking to reduce false positives while preserving line/column references.varlock auditschema/code drift detection with CI-friendly exit codes and correct--pathscan-root behavior for file and directory inputs.# @auditIgnorePaths(...)is collected viagetRootDecFns, merged across calls/imports, flattened from positionalarrargs, normalized, and passed as additive scanner excludes.# @auditIgnoresuppresses only unused-in-schema reporting when strictlytrue;# @auditIgnore=falsedoes not suppress.Validation
bun run --filter varlock typecheckbun run --filter varlock test src/cli/commands/test/audit.command.test.tsbun run --filter varlock test src/cli/helpers/test/env-var-scanner.test.tsbun run --filter varlock test:ci