ISSUE DESCRIPTION Stale-detection timestamp-field allowlist misses spec-declared date…
- User
ISSUE DESCRIPTION
Stale-detection timestamp-field allowlist misses spec-declared date fields Retro finding · priority: P2 · component: generator · source: Trello CLI generation (printing-press 4.9.0)
What happened
The generated
internal/cli/pm_stale.gomatches inactivity against a hardcodedstaleTimestampFieldsallowlist (updatedAt, updated_at, updatedDate, modifiedAt, modified_at, lastModified, last_modified, lastEditedTime, last_edited_time, updated, last_updated). Trello cards usedateLastActivity, which is absent. The flagshipstalecommand returned "No stale items found" while a hand-builthealthcommand (readingdateLastActivity) counted 93 stale cards on the same hydrated data. Silent-empty flagship command, no error.Root cause
The stale template hardcodes a timestamp-name allowlist instead of also deriving candidate timestamp fields from the spec (properties with
format: date-time).Durable fix (proposed)
Build the stale timestamp-field set as
hardcoded allowlist ∪ spec-declared date-time property names for the synced resources. Guard: union is additive only — never removes existing allowlist entries, so no regression for currently-working APIs.Test
- Positive: a spec with a
dateLastActivity(format: date-time) card property produces astalethat finds rows older than N days. - Negative: an API using
updated_atis unchanged.
Repro / evidence
trello-pp-cli stale --days 14→ empty;trello-pp-cli health→ 93 stale on the same mirror. Fixed by hand-addingdateLastActivityto the allowlist. The allowlist approach will keep silently breaking the flagship command for the next API with an unlisted activity field.Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call ) using or commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. - Positive: a spec with a
Assistant
Let me explore the repository structure first.
Assistant
Now I understand the structure. The template hardcodes
staleTimestampFields. I need to make the generator derive additional timestamp fields from the spec (properties withformat: date-time), and add them to the allowlist in the generated template.Let me look at how the generator works, how templates are rendered, and what data is available.
Assistant
Let me look at where pm_stale template is rendered and what data is passed.
Assistant
Now let me find where the pm_stale template is invoked/rendered and what data is passed.
Assistant
The workflow templates render with
g.Spec. I need to add spec-declared date-time fields. Let me look at the spec structure.Assistant
Let me find where response fields/properties with formats are stored in the spec.
Assistant
So the spec has a
Typesmap withTypeDefcontainingFields []TypeFieldeach having aFormat. So I can derive date-time fields from the spec's Types.But also endpoint response fields might have properties with date-time. Let me look at how the schema_builder constructs the TableDef (which is what's used for sync resources). Let me look at the schema_builder.go to understand the field names of synced resources.
Actually, the key is: I need to derive the spec-declared date-time property names for the synced resources. The synced resources are
g.profile.SyncableResources. Let me understand what fields they expose.Let me look at the schema_builder.go and TableDef.
Assistant
Let me look at the column derivation and where fields/properties with format come from. The schema builds columns with a Format. Let me look at the ColumnDef - it doesn't store Format. Let me look at the field collection logic more.
Assistant
So
collectResponseFieldsreturns fields with format. I need to derive the spec-declared date-time field names for the synced resources and pass them to the stale template. Let me check the template functions and how data flows.Assistant
Let me check what
SyncableResourcecontains and how to map resources to their response fields.Assistant
Let me check how sub-resource fields are collected.
Assistant
Let me check the golden test structure and whether pm_stale.go is part of golden fixtures that might change.
Assistant
No pm_stale.go in golden fixtures. So the golden tests don't include the stale command. Let me verify which tests render pm_stale template and how. Let me check the testdata golden structure and how golden tests work.
Assistant
So pm_stale is only generated for "project-management" archetype. Let me check the golden test specs that have project-management archetype to see if they have date-time fields and would change output. But there are no pm_stale.go in golden expected dirs, so golden tests don't render this template currently. Wait, let me check - maybe the golden tests are run via the generator and compared. Let me look at how golden tests are structured and what archetype the test specs have.
Let me search for golden test specs that use project-management archetype and have date-time fields.
Assistant
Let me check the golden-api spec and how golden tests render workflows.
Assistant
Let me look at the golden-api.yaml to understand its archetype and date-time fields.
Assistant
Let me check whether any golden expected directory contains pm_stale.go and how golden tests compare.
Assistant
So no golden expected file contains pm_stale.go. That means golden-api (project-management archetype?) doesn't render pm_stale in golden tests, OR the golden tests don't check pm_stale. Let me verify by checking the generate golden test that uses golden-api.
Let me check the archetype of golden-api and whether it has pm_stale generated in its expected output. Let me look at the expected golden-api directory.
Assistant
No pm_stale.go in the golden-api expected. Let me look at the generator_test around the pm_stale rendering tests.
Assistant
Let me look at the
minimalSpechelper and any existing test for the spec-derived union.Assistant
Let me search for any existing test that checks the generated pm_stale.go content for spec-derived fields.
Assistant
No existing test for the spec-derived union. Let me run the relevant existing tests first to establish a baseline.
Assistant
Let me check the golden tests to ensure my change won't break them. Let me find which golden tests use project-management archetype.
Assistant
Let me find the golden comparison tests.
Assistant
No test references the golden expected dirs. So those expected dirs might be fixtures created by running the generator manually, or used by a different test mechanism. Let me search more broadly.
Assistant
The golden-api case does NOT generate pm_stale.go. Let me confirm no golden case generates pm_stale.go.
Assistant
No golden cases generate pm_stale.go. Now let me check all places that render the pm_stale template.
Assistant
Let me check the scorecard.go reference to pm_stale.go.
Assistant
Now let me look at the exact loop to modify.
Assistant
Let me check the imports in generator.go.
Assistant
Let me check if any test renders pm_stale directly with g.Spec.
Assistant
All execution tests go through
gen.Generate(). Now let me implement. First, modify the loop inrenderWorkflowFiles.Assistant
Let me verify the Generator struct has a
profilefield.Assistant
Good,
profile *profiler.APIProfileexists. Let me check the fields SyncableResources and DependentResources on APIProfile.Assistant
The field is
DependentSyncResources, notDependentResources. Let me fix that.Assistant
Let me check where
g.profileis populated in Generate.Assistant
Let me add a nil guard for
g.profilein the helper.Assistant
Now let me modify the template to append the extra fields.
Assistant
Now let me modify the template to append spec-declared fields and update the comment.
Assistant
Now let me build the generator package to check for compile errors.
Assistant
Builds. Now let me write a temporary test to verify the fix. First, let me understand the Endpoint.Response structure.
Assistant
Now let me write a temporary test to verify the fix.
Assistant
The
dateLastActivityis in the allowlist (the earlier assertion passed). Thejson_extractassertion is wrong because the SQL is built at runtime viafmt.Sprintf. Let me check the generated var.Assistant
The generated
staleTimestampFieldsnow includesdateLastActivity. Thejson_extractassertion was wrong (SQL built at runtime). Let me fix the repro test and also verify the generated code actually finds stale rows by compiling and running it.Assistant
All three repro tests pass. Now let me do an end-to-end runtime test: generate a full project-management CLI, build it, populate the store, and run
stale. Let me check the test helpers for building generated CLIs.Assistant
Let me check which SQLite driver the generated CLIs use, to do a focused runtime test of the predicate.
Assistant
Let me check how the generated go.mod is constructed and whether deps are available offline.
Assistant
modernc.org/sqlite and cobra are in the module cache. Let me do an end-to-end runtime test. First, let me check the store.Open signature in the template.
Assistant
The Store wraps *sql.DB. Let me check the Store struct to access the underlying db for direct inserts, or use the store's methods. Actually, the stale command uses
store.OpenWithContextwhich returns*store.Store, thendb.Query(...). So Store must expose Query or be a wrapper. Let me check.Actually, in the template pm_stale.go, it does
db, err := store.OpenWithContext(...)thendb.Query(query, qArgs...). So*store.Storehas aQuerymethod (or embeds *sql.DB). Let me check.Assistant
Let me check that
Upsertwrites to theresourcestable (which stale queries).Assistant
Let me check that
store.Opencreates theresourcestable via migrate.Assistant
Let me write an end-to-end runtime test that generates a full CLI, adds a runtime test inside it, and runs it.
Assistant
Let me write an end-to-end runtime test that generates a full CLI, adds a runtime test inside it, and runs it.
Assistant
The days=30 "failure" is actually correct staleness logic — a 20-day-old card is NOT stale at a 30-day threshold (20 < 30). My test expectation was wrong. Let me fix the runtime test with correct staleness semantics.
Assistant
Let me simplify the runtime test to avoid the sort import issue.
Assistant
Let me rewrite the entire e2e test file cleanly with a minimal runtime test that doesn't use sort.
Assistant
The end-to-end runtime test passes — the generated
stalecorrectly finds rows usingdateLastActivity. Now let me clean up the temp test files and run the existing tests.Assistant
Now let me run the existing stale-related generator tests to ensure no regressions.
Assistant
Let me run the broader generator test suite to check for regressions.
Assistant
The failure is in
TestGenerateWithNoAuth— a govulncheck scan finding a stdlibcrypto/tlsvulnerability (GO-2026-5856), unrelated to my change. Let me confirm it fails without my changes too.Assistant
Confirmed —
TestGenerateWithNoAuthfails on the unmodified codebase too (pre-existing govulncheck stdlib vuln). Not caused by my change. Let me clean up the stray build artifact dir and run the rest of the generator tests, skipping that pre-existing failure.Assistant
Let me identify which test(s) failed.
Assistant
The failures (
TestGoBuildCacheDirIsShared,TestGoBuildCacheDirPath,govulncheck) are environmental — caused by myGOCACHE/GOPATHenv overrides, not my code change. Let me verify by running them with a clean environment (no GOCACHE override).Assistant
TestGoBuildCacheDirPathfails with "HOME`). Let me set HOME and run without the GOCACHE override.Assistant
Those pass with proper
HOMEand noGOCACHEoverride — environmental. The only remaining failures are govulncheck-based (stdlib vuln in go1.26.4), which fail pre-change too. Let me find which test runsgovulncheck ./....Assistant
The govulncheck failures are environmental (stdlib vuln). Let me run the tests most likely affected by my change — framework_collision (builds a generated CLI with pm_stale) and template tests.
Assistant
Let me run the full generator suite, skipping tests that invoke govulncheck/Validate (environmental). Let me find them.
Assistant
TestGenerateWithNoAuthruns the real govulncheck (environmental). Thevalidate_test.gouses a fakego. Let me run the full generator suite, skipping the known environmental tests (TestGenerateWithNoAuth, build-cache tests), with proper env.Assistant
All generator tests pass (except the 3 known environmental ones). Let me also run other potentially-affected packages (catalog with asana/jira project-mgmt specs, pipeline/scorecard, cli).
Assistant
Let me run the cli package tests (scorecard references pm_stale.go).
Assistant
Let me run the golden verification suite to ensure no golden output changed. First, build the binary.
Assistant
Many golden cases fail, but none involve pm_stale.go — they span README.md, client.go, mcp/tools.go across non-project-management cases. This suggests pre-existing/environmental diffs. Let me inspect one diff and confirm by running golden verify on the stashed (original) code.
Assistant
The diff is an environmental golden-normalization artifact: the repo-root basename
cli-printing-pressappears inside the hardcodedgithub.com/mvanhorn/cli-printing-pressURL, and the normalizer replaces/cli-printing-press→<REPO>, yieldinggithub.com/mvanhorn<REPO>. This is unrelated to my change (I didn't touch headers/URLs). Let me confirm by stashing my changes and running the same golden verify.Assistant
Confirmed: the SAME 16 golden cases fail on the unmodified codebase — these are pre-existing environmental normalization artifacts, not caused by my change. My change introduces zero new golden failures. Let me clean up the build artifacts I created.
Assistant
Now let me review the final diff of my changes.
Assistant
The diff is clean and complete. Let me verify the OpenAPI parser populates
Format: "date-time"on TypeFields (so the fix works for OpenAPI-derived specs like Trello's).Assistant
The OpenAPI parser populates
Formatfromschema.Format. Let me do a final OpenAPI-based end-to-end test (Trello uses OpenAPI): create a minimal OpenAPI spec withdateLastActivity, generate via the binary, and confirm the generatedpm_stale.goincludes it.Assistant
pm_stale.go wasn't generated — the archetype wasn't detected as project-management. Let me check what was generated and the archetype detection.
Assistant
Let me check how the project-management archetype is detected to craft a spec that triggers pm_stale generation.
Assistant
"card" isn't a PM keyword, but "board" is. Let me add a
boardsresource to trigger the project-management archetype (realistic for Trello).Assistant
The OpenAPI-derived generation now includes
dateLastActivityinstaleTimestampFields. Let me confirm the generated Trello CLI compiles, then run a realstaleagainst a populated DB.Assistant
The generated Trello CLI builds. Let me check for a
sqlsubcommand to populate the store, then runstale.Assistant
Let me write a runtime test inside the generated Trello CLI that exercises the actual
stalecobra command (matching the issue repro). Let me check rootFlags.Assistant
Let me write a runtime test inside the generated Trello CLI that exercises the actual
stalecobra command.Assistant
The actual
trello-pp-cli stale --days 14cobra command now finds the stale card viadateLastActivityand no longer returns empty. This matches the issue's repro exactly. Let me clean up /tmp artifacts and do a final check for any other places that hardcode the allowlist.Assistant
Let me run
go veton the generator package and a final compile check across the repo.Assistant
Let me verify the working tree is clean of any temp files and review the final state.
Assistant
All changes are clean and complete. Let me do a final review of the complete diff.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.