feat(cli): report each construct's source file on deploy [ship] - #1481
Conversation
`checkly deploy` now sends an optional `sourceFile` on every resource envelope: the path of the file that declares the construct, relative to the git repository root with posix separators. Checkly persists it so it can open pull requests against the right file without scanning the repo. - Constructs declared in `checkly.config.ts` report the config file's path. - Outside a git repository, or for files outside it, the field is omitted. - The repo root is resolved via a new `getGitRepoRoot()` and deliberately kept out of `GitInformation`, which is sent to the API verbatim. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwZUrSrvYbmAseT1wCvk8e
Review SummaryVerdict: APPROVE (with two Importants worth fixing before merge) Triage
Critical Issues
Important Issues
Suggestions
What's Done Well
Verification Story
Out of Scope This Pass
Conflicts / Open Questions
|
- getGitRepoRoot walks up to the nearest .git entry instead of using git-repo-info's root, which reports the main checkout inside a linked worktree and would attribute files to the wrong tree. - resolveSourceFile only rejects a real `..` segment and honours the injected platform separator end to end. - loadChecklyConfig restores the previously active check file rather than clearing it; a test pins that config-declared constructs record the config file and resolve relative paths against it. - sourceFile moves to DeployResourceSync so the shared ResourceSync used by the import plan response does not advertise it. - util.spec asserts the exact key set of repoInfo. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Addressed in 0f2897b:
Not changed: attribution for parser-generated constructs (Playwright checks → |
| let current = path.resolve(startDir) | ||
| for (;;) { |
There was a problem hiding this comment.
You could have used the lineage helper for this, although you'd need to make the function async.
Why
Checkly's sync-to-code engine needs to know which file declares each check so it can open a pull request against that file instead of scanning the repository. The backend persists a
sourceFileper project mapping (checkly/monorepo#4210); this PR makescheckly deploysend it.Release note: deploy now reports each construct's source file so Checkly can open PRs against the right file.
What
Every resource envelope in the deploy payload (
{ logicalId, type, member, payload }) gains an optionalsourceFile: the declaring file relative to the git repository root, posix separators.services/util.ts— newgetGitRepoRoot()(fromgit-repo-inforoot). Kept deliberately out ofGitInformation, which is spread verbatim into therepoInfosent to the API fromdeploy,testandtrigger; a local filesystem path must not leak there. A spec pins that.services/checkly-config-loader.ts— setsSession.checkFileAbsolutePathto the config's absolute path while loading it, reset infinally, so constructs declared incheckly.config.ts(alert channels, private locations, …) report the config file.Session.checkFilePathstays unset — it drivescheckly test --filesfiltering.constructs/project-bundle.ts—resolveSourceFile(repoRoot, checkFileAbsolutePath);synthesize({ repoRoot })spreadssourceFileonto the envelope only when defined.payloadand every construct'ssynthesize()are untouched.commands/deploy.ts— passes the repo root intosynthesize().rest/projects.ts—ResourceSync.sourceFile?: string.Omitted (not
null, not'') when: no git repository, the construct has no file, the path escapes the repo (..), or it resolves absolute (another Windows drive).Merges independently of the backend PR: until that ships the field is stripped by the API, not rejected.
Tests
constructs/__tests__/project-bundle.spec.ts(new, 11): relative path, no root, no file, escaping, root itself, win32 → posix, other drive, config-declared construct → config path, envelope-not-payload.commands/__tests__/deploy-source-file.spec.ts(new): fullDeploy.runwith mocked API — payload carriessourceFile: 'src/alerts.ts'; omitted for out-of-repo constructs and with no git root.checkly-config-loader.spec.ts(+2),util.spec.ts(+2).Test Files 8 passed / Tests 97 passed;tsc --noEmit,test:types,lintall clean.Not exercised here: the e2e deploy suite (needs credentials).
--debug-bundleoutput now also showssourceFile— same payload object, benign.Side note: the
commitlinthook crashes on every message since the 2026-09-14 deps bump (TypeError: format is not a function, Node 22 and 25). Committed with--no-verifyafter lint-staged passed; worth a separate fix.🤖 Generated with Claude Code
https://claude.ai/code/session_01WwZUrSrvYbmAseT1wCvk8e