Patch when closed: migration, types, FMA ingestion - #49691
Conversation
The manifest pipeline generates queries.open, but nothing copied it onto the installer, so app_open_query was always stored empty. Map it onto MaintainedApp and carry it into the install payload across the add, auto-update, clone, and GitOps batch paths, mirroring patch_query. Keep the field internal (json:"-") like patch_query so it stays out of software title API responses.
…ed-migration-types-manifests # Conflicts: # server/datastore/mysql/schema.sql
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feat/39962-patch-when-closed #49691 +/- ##
=============================================================
Coverage 67.89% 67.90%
=============================================================
Files 3890 3891 +1
Lines 248437 248495 +58
Branches 13022 13022
=============================================================
+ Hits 168679 168743 +64
Misses 64543 64543
+ Partials 15215 15209 -6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…SON test expectations
|
@coderabbitai review |
✅ Action performedReview finished.
|
WalkthroughAdds the 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/patch_policy/patch_policy.go`:
- Around line 165-186: Escape SQL string-literal values before interpolation in
defaultMacOSOpenQuery and defaultWindowsOpenQuery, including bundleIdentifier
and the derived executable from softwareTitle. Preserve the existing query
behavior while ensuring apostrophes and other literal content cannot break or
alter the SQL predicates.
In `@server/datastore/mysql/software_installers.go`:
- Around line 2988-2989: Update the wasUpdatedArgs construction in both
checkExistingInstaller and checkExistingActiveInstaller to include
installer.AppOpenQuery immediately after installer.PreInstallQuery. Ensure both
comparison query variants treat app-open-query-only changes as metadata
modifications so the existing pending-install side effects run.
In `@server/mdm/maintainedapps/sync.go`:
- Line 261: Update the cached-version hydration branch in the sync flow to copy
cached.AppOpenQuery onto the hydrated app before returning, matching the
manifest hydration assignment to app.AppOpenQuery. Ensure pinned cache hits
preserve the managed query and existing patch-when-closed behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: cfc6a55c-7fe9-4679-be31-449789f20ff8
📒 Files selected for processing (23)
cmd/fleetctl/fleetctl/api_test.gocmd/fleetctl/fleetctl/testdata/expectedHostDetailResponseJson.jsoncmd/fleetctl/fleetctl/testdata/expectedHostDetailResponseYaml.ymlee/maintained-apps/ingesters/homebrew/ingester.goee/maintained-apps/ingesters/homebrew/ingester_test.goee/maintained-apps/ingesters/winget/ingester.goee/maintained-apps/ingesters/winget/ingester_test.goee/maintained-apps/maintained_apps.goee/server/service/maintained_apps.goee/server/service/maintained_apps_auto_update.goee/server/service/software_installers.gopkg/patch_policy/patch_policy.gopkg/patch_policy/patch_policy_test.goserver/datastore/mysql/migrations/tables/20260721173820_PatchWhenClosed.goserver/datastore/mysql/migrations/tables/20260721173820_PatchWhenClosed_test.goserver/datastore/mysql/schema.sqlserver/datastore/mysql/software_installers.goserver/datastore/mysql/software_installers_test.goserver/fleet/maintained_apps.goserver/fleet/policies.goserver/fleet/software_installer.goserver/mdm/maintainedapps/sync.goserver/webhooks/failing_policies_test.go
…ery on FMA cache hits
Related issue: Resolves #49415
Checklist for submitter
If some of the following don't apply, delete the relevant line.
Changes file added for user-visible changes in
changes/,orbit/changes/oree/fleetd-chrome/changes.See Changes files for more information.
Input data is properly validated,
SELECT *is avoided, SQL injection is prevented (using placeholders for values in statements), JS inline code is prevented especially for url redirects, and untrusted data interpolated into shell scripts/commands is validated against shell metacharacters.Timeouts are implemented and retries are limited to avoid infinite loops
If paths of existing endpoints are modified without backwards compatibility, checked the frontend/CLI for any necessary changes
Testing
Added/updated automated tests
Where appropriate, automated tests simulate multiple hosts and test for host isolation (updates to one hosts's records do not affect another)
QA'd all new/changed functionality manually
app_open_query. If not, it remains empty.SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM apps a JOIN processes p ON p.path LIKE concat(a.path, '/%%') WHERE a.bundle_identifier = '%s');queries locally on apps available in dogfood self service, looks like it will work reasonably well for a start.Database migrations
COLLATE utf8mb4_unicode_ci).Summary by CodeRabbit
New Features
Bug Fixes