feat(pgpm): init refreshes stale template cache, scaffolds in place, fixes RLS testing docs - #1840
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
This PR enhances
Reviewed commit: 8611bf7 |
There was a problem hiding this comment.
Adds remote-template cache refresh and in-place scaffolding to the pgpm init command, with TTY detection and template-source cache invalidation improvements.
Key findings
- 🟡 Folding every
ls-remotefailure intooffline— template-scaffold.ts:232
| } catch { | ||
| const info = { | ||
| repo: url, | ||
| branch, | ||
| refreshed: false, | ||
| offline: true, | ||
| local: false, | ||
| }; | ||
| templateRefreshMemo.set(memoKey, info); | ||
| return info; | ||
| } |
There was a problem hiding this comment.
🟡 bug · medium
Folding every ls-remote failure into offline
In refreshTemplateCache the catch around git ls-remote (pgpm/core/src/core/template-scaffold.ts:232) converts every failure — network outage, auth error, missing git, or a nonexistent branch — into offline: true / refreshed: false and returns without clearing the stale clone. Callers like pgpm init then print using <repo> (offline, using cached copy) and scaffold from the old cache.
The explicit offline path is the PGPM_TEMPLATE_OFFLINE branch (lines 210-220); folding every other error into it means a mistyped branch or a transient fetch failure is silently reported as offline, and the result is memoized for the process lifetime, so an explicit --refresh silently serves stale content instead of failing loudly.
📋 Prompt for AI Agents
In pgpm/core/src/core/template-scaffold.ts lines 222-242, the try/catch around execFileSync('git', ['ls-remote', ...]) swallows every failure into an offline: true, refreshed: false result and memoizes it, so a forced --refresh silently serves the stale clone and the process never retries. Change the catch so it only treats a failure as offline when process.env.PGPM_TEMPLATE_OFFLINE is set (that path is already handled at lines 210-220); for any other failure, throw a descriptive error containing the repo/branch and underlying message, and do not memoize a permanent offline result for transient failures. Before returning an offline success, also confirm fs.existsSync(path.join(cm.getReposDir(), key)) so describeTemplateSource does not claim 'using cached copy' when no clone exists.
Summary
Addresses the
constructiveside of constructive-io/constructive-planning#2077 (items 1, 3, 5). Thepgpm-boilerplatesside (CI matrix discovery + template smoke test) is a separate PR.Stale template cache.
genomic'sTemplateScaffoldercaches a shallow clone (with.gitremoved) and only re-clones after a 1-day TTL, so a template change never shows up until the entry expires. NewrefreshTemplateCache()in@pgpmjs/coreruns before everyinspectTemplate/scaffoldTemplateinpgpm init:pgpm init --refresh/--no-cacheforces the re-clone.using constructive-io/pgpm-boilerplates@HEAD (abc1234, fetched 2m ago)(describeTemplateSource), with(offline, using cached copy)when the check couldn't reach the remote.Nested scaffold dir.
pgpm init workspace --name foorun inside an empty directory (or one containing only.git) already namedfoonow scaffolds in place instead of creatingfoo/foo(isScaffoldableInPlace). The trailingcd ./…hint is omitted when the target is cwd.Non-TTY.
isNoTtyRequested/detectNoTtyFromProcessalso treatprocess.stdin.isTTY !== trueas non-interactive, so piped/CI invocations fail fast on missing required answers instead of hanging on a prompt. Help text notes that non-interactive runs must answer every question via flags.Docs.
pgpmskilltesting.md:setContexttakes an object (db.setContext({ role: 'authenticated', 'jwt.claims.user_id': 'user-1' })), new "RLS testing" section with the schema/table/sequence grants needed before RLS is reached, and a note thatpg/dbare separate connections.cli.md:--refreshand pointer to the non-interactive flag table.Tests:
pgpm/core/__tests__/template-refresh.test.ts(bare repo fixture: refresh on new remote commit, no-op when unchanged, force, offline, describe format), in-place workspace init test, tty test.Link to Devin session: https://app.devin.ai/sessions/dd4055c50bcf4b1e8e604211038aaa82
Open in Devin Desktop: https://app.devin.ai/desktop/session/dd4055c50bcf4b1e8e604211038aaa82?variant=devin
Requested by: @pyramation