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 start by exploring the repository structure to understand the codebase and find the relevant files related to the stale-detection issue.
Assistant
Let me find the stale-related files and templates.
Assistant
The template file is at
/cli-printing-press/internal/generator/templates/workflows/pm_stale.go.tmpl. Let me explore the repository structure first to understand it better.Assistant
Let me open the stale template file to understand the current implementation.
Assistant
Now I understand the issue. The
staleTimestampFieldsis a hardcoded list that doesn't includedateLastActivityor other spec-declared date-time fields. Let me explore the generator to understand how templates are processed and how the spec data is available.Assistant
Let me look at the generator.go file to understand how templates are processed and what data is available to them.
Assistant
Let me look at the spec package to understand the data model available to templates:
Assistant
Now let me look at the spec.go file to understand the data model, especially the resources and properties with
format: date-time.Assistant
Let me look at the Resource struct definition.
Assistant
Now let me look at the Resource struct and its properties:
Assistant
Let me look at the TypeDef to understand how properties with
format: date-timeare defined:Assistant
Now let me look at the TypeDef struct:
Assistant
Let me understand how the templates are rendered and what data is available. Let me look at how the generator renders templates:
Assistant
Let me look at the context around line 3184 to understand how the template is rendered:
Assistant
Now let me look at how templates receive their data:
Assistant
Let me see the generatorTemplateData and how templates receive their data:
Assistant
Now I need to understand how templates are called. Let me see how
generateTemplateDataor similar is called to understand what data is passed to templates.Assistant
Let me search for how the template data is structured for rendering templates:
Assistant
Let me look at what
generatorTemplateDatacontains and how templates receive their data:Assistant
Let me look at the APISpec struct to understand the data model:
Assistant
Let me understand how the generator passes data to templates, particularly looking at how the template data flows:
Assistant
Now I need to understand how the pm_stale.go.tmpl template receives its data. Let me look at where workflow templates are rendered.
Assistant
I need to look at the renderWorkflowFiles function to understand how the pm_stale template is rendered and what data is passed to it. Let me check around line 2695.
Assistant
Now I understand. The workflow templates receive
g.Specas their data, which gives access toResourcesandTypes. I need to modify the template to build thestaleTimestampFieldsallowlist as the union of the hardcoded list AND spec-declareddate-timeproperty names.Let me look at how YAML specs define types with
format: date-time:Assistant
Now I have a good understanding of the codebase. Let me look at how the template receives its data and examine existing patterns for building dynamic lists in templates:
Assistant
Let me examine how other template functions work in the generator, particularly ones that embed computed Go values:
Assistant
Let me look at how
enumLiteralis used in templates to understand the pattern for embedding computed Go literals:Assistant
Now I have a clear understanding. Let me look at how to properly implement this fix. The approach will be to:
- Add a template function that extracts all
date-timeformatted property names from the spec's Types - Modify the
pm_stale.go.tmpltemplate to use this function alongside the hardcoded list
Let me look at the test file to understand what tests exist for the stale command:
- Add a template function that extracts all
Assistant
Let me look at more of the tests for stale:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '12820,12920p' /cli-printing-press/internal/generator/generator_test.go </tool_call>
Assistant
Let me continue exploring the test file to understand the current tests for the stale command.
Assistant
Now I have a thorough understanding of the codebase. Let me summarize my plan:
Issue: The
staleTimestampFieldsallowlist inpm_stale.go.tmplis hardcoded and doesn't include spec-declaredformat: date-timefields likedateLastActivity.Fix approach:
- Add a template function that extracts all property names with
format: date-timefrom the spec's Types - Modify the template to use this function to add spec-derived date-time fields to the hardcoded allowlist
Let me first look at more detail of how template functions work in this codebase:
- Add a template function that extracts all property names with
Assistant
Now I have a clear understanding. Let me implement the fix.
Plan:
- Add a template function
staleTimestampFieldsthat returns all stale timestamp field names (hardcoded allowlist + spec-declaredformat: date-timeproperty names) - Modify
pm_stale.go.tmplto use this function instead of the hardcoded list
Let me start by adding the template function to generator.go:
- Add a template function
Assistant
Now let me implement the fix. I'll add a template function to extract date-time fields from the spec and modify the template to use it.
Assistant
Let me now create the fix. I need to:
- Add a new template function that extracts date-time field names from the spec's Types
- Modify the pm_stale.go.tmpl template to use this function
Let me look at the current pm_stale.go.tmpl template again to understand the exact format needed:
Assistant
Now I'll implement the fix. The approach is:
- Add a template function
dateTimeSpecFieldsthat extracts allformat: date-timefield names from the spec's Types - Modify the
pm_stale.go.tmpltemplate to build the allowlist ashardcoded ∪ spec-declared date-time fields
- Add a template function
Assistant
Now I'll add a template function to extract
format: date-timefield names from the spec's Types, then modify the template to use it.Assistant
Let me add the template function and modify the template. First, I'll add the helper function to generator.go:
Assistant
Let me use the correct edit command syntax.
Assistant
The edit command requires a file to be open first. Let me use the --file option instead.
Assistant
Let me check the current state of the file:
Assistant
I see the edit messed up the file - it's missing the closing
},after thehasNonScalarTypefunction. Let me fix this.Assistant
Good, the
specDateTimeFieldstemplate function is now added. Now I need to modify thepm_stale.go.tmpltemplate to use this function to append spec-declared date-time fields to the hardcoded allowlist.Assistant
Now I need to modify the pm_stale.go.tmpl template to append spec-declared date-time fields to the hardcoded allowlist. The cleanest approach is to add an
init()function that appends the spec-declared date-time fields to the hardcoded list.Assistant
Now let me copy the new template to the correct location:
Assistant
Let me verify the template was written correctly:
Assistant
The template has been updated. Now let me run the tests to verify the changes work correctly.
Assistant
Let me check the Go environment:
Assistant
I need to set up Go environment variables to run the tests. Let me check if there's a go.mod file and try to set up the environment properly.
Assistant
The environment variables are partially set but still missing GOCACHE. Let me try again with all the necessary environment variables.
Assistant
No tests matched the pattern. Let me search for the actual test function names related to stale:
Assistant
The test is at line 13040. Let me search for more stale-related tests and also look at the test function TestStaleTemplateCoversCommonTimestampFields.
Assistant
Let me now search for and run more related tests:
Assistant
Let me run all the tests related to stale, PM workflows, and templates:
Assistant
All tests pass. Let me also run the
TestPMWorkflowCommandEmitsSyncHintstest:Assistant
The test name is
TestPMWorkflowCommandEmitsSyncHintsbut it seems the test is in a different file. Let me check.Assistant
Let me check the exact test name by viewing that function.
Assistant
The test name matches. Let me try running it with the full test name pattern.
Assistant
The test exists but doesn't match. Let me investigate why.
Assistant
The test function name has "TestPMWorkflow" in it but the test runner isn't finding it. Let me check if the file is being compiled correctly and what's happening with this test.
Assistant
Let me check if there's a build error in the generator code:
Assistant
The generator builds successfully. Let me check what's happening with the test function - it might be in a build tag or conditional compilation section:
Assistant
Let me check if the test file has build tags:
Assistant
The test function exists and there are no build tags. Let me try a different approach - maybe the issue is with how go test is finding the test function. Let me run all tests in the package to see if there are any issues.
Assistant
It seems like the test isn't being found. Let me check if the test function is in a file that gets built differently or has some special conditions.
Assistant
I see - the test function exists but it's in generator_test.go. Let me try running it with the exact name:
Assistant
The test exists in the generator_test.go file but it seems to not be found. This could be because the test depends on the
root.gowhich is generated at build time, not compiled into the test. Let me check if there's a dependency issue.Assistant
The test uses
RootCmd()which is from the generated code, not the test code. This might be causing issues. But that's not critical for our fix. The key tests that pass are the ones that test the template rendering. Let me focus on verifying the fix works by running a simple test that generates the code and checking if the output contains the expected fields.Let me create a simple test script to verify the fix works correctly.
Assistant
The test
TestPMWorkflowCommandEmitsSyncHintsis not being found by the test runner. Let me check if there's an issue with the test file.Assistant
I see now -
TestPMWorkflowCommandEmitsSyncHintsis actually a string inside a test that checks for generated code content, not an actual test function. Let me verify my fix is working by running the relevant tests:Assistant
All tests pass. Now let me look at the
TestStaleTemplateCoversCommonTimestampFieldstest to understand how the template output is verified:Assistant
All tests pass. Now let me write a simple test to verify the fix handles specs with
format: date-timefields correctly:Assistant
Let me fix the test script - the import is not used.
Assistant
The fix is working correctly. Now let me run the broader test suite to make sure the changes don't break anything else:
Assistant
The test failure is unrelated to my changes - it's a Go standard library vulnerability (crypto/tls) detected by
govulncheck. This is a pre-existing issue, not caused by my fix. Let me run only the tests relevant to the stale template to confirm my changes work correctly:Assistant
All the tests pass. Let me also verify the fix works for an actual spec with
format: date-timefields by running a more comprehensive test:Assistant
Let me also write and run an integration test to verify the fix works end-to-end with a spec containing
format: date-timefields:Assistant
The file name ends with
_test.gobut I'm trying to run it withgo run. Let me rename it.Assistant
Let me check what's the correct command to invoke the generator.
Assistant
Let me check how the generator is invoked and continue testing:
Assistant
Let me look at how the generator is actually invoked:
Assistant
Let me look at how tests invoke the generator:
Assistant
Let me verify the template syntax by checking if there are any template compilation errors:
Assistant
The test didn't find a matching test. Let me check if there's a test that verifies template compilation.
Assistant
The test
TestTemplatesEmitReadOnlyAnnotationexists. Let me run it to verify the template compiles correctly.Assistant
The template compiles successfully. Now let me verify the fix by running all the workflow-related tests:
Assistant
All tests pass. Let me now verify the complete changes I've made:
Assistant
Let me verify the exact changes made:
Assistant
All the changes are in place and the tests pass. Let me provide a summary of the changes made:
Summary of Changes
Issue
The
stalecommand in CLI Printing Press was missing spec-declaredformat: date-timefields (like Trello'sdateLastActivity) from its stale-detection timestamp allowlist, causing the command to return "No stale items found" when such fields were used.Fix
Modified two files:
-
internal/generator/generator.go: Added a new template functionspecDateTimeFieldsthat extracts all fields withformat: date-timefrom the spec's Types map. -
internal/generator/templates/workflows/pm_stale.go.tmpl:- Renamed
staleTimestampFieldstostaleTimestampDefault(preserving the hardcoded allowlist) - Added a new
staleTimestampFieldsvariable built in an function
- Renamed
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.