Skip to content

fix(platform-config): send full config payload on update (FT-1941)#38

Open
joalves wants to merge 8 commits into
mainfrom
feat/FT-1941/platform-config-update-fix
Open

fix(platform-config): send full config payload on update (FT-1941)#38
joalves wants to merge 8 commits into
mainfrom
feat/FT-1941/platform-config-update-fix

Conversation

@joalves
Copy link
Copy Markdown
Collaborator

@joalves joalves commented May 21, 2026

Summary

Fixes FT-1941. abs platform-config update <id> --value <json> was returning HTTP 500 (Cannot use 'in' operator to search for 'archived' in 30) because the CLI was sending {"data": <raw-value>} instead of the required {"data": {"name": "...", "value": "...", ...}}.

  • Core (src/core/platformconfig/platformconfig.ts): now GETs the current config, merges the new value over it, drops id (it's in the URL path), and PUTs the full object. UpdatePlatformConfigParams.value is now unknown so the CLI can pass any JSON value (string, number, object, array).
  • CLI (src/commands/platformconfig/index.ts): dropped the misleading as Record<string, unknown> cast on validateJSON(--value). Config values in the wild are often non-object JSON ("30", 42, booleans).
  • API client (src/api-client/api-client.ts): unchanged. Investigation showed { data: { data } } is JS shorthand producing the correct { data: <param> } wire body; the original bug was upstream. Added a regression test that pins the wire shape so a future refactor can't reintroduce the symptom.

Test plan

  • npx vitest run src/core/platformconfig src/commands/platformconfig src/api-client — 10/10 platform-config tests + the api-client regression guard pass
  • npx vitest run (full suite) — 2382/2382 pass, 4 skipped
  • npx tsc --noEmit — clean
  • Live verified against dev-1: GET→PUT round-trip on configs 22 (experiment_form_max_secondary_metrics) and 23 (experiment_form_max_guardrail_metrics); both returned 200, updated_at advanced, all fields preserved
  • --show-request output confirms the wire body is {"data": {"name": "...", "value": "30", "default_value": ..., ...}}

Summary by CodeRabbit

  • Bug Fixes

    • Platform config updates now merge new values into existing configurations and preserve other fields.
    • Improved error reporting when the target config cannot be found or is malformed.
  • New Behaviour

    • Update accepts a wider range of JSON value types (numbers, strings, objects and falsy values) and forwards them correctly.
  • Tests

    • Expanded test coverage for update scenarios, error cases and value-type handling.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Walkthrough

This pull request changes platform config updates to read-before-write: updatePlatformConfig now GETs the existing config, ensures it's a non-null object, removes its id, merges the provided value into the remaining fields, and PUTs the merged record (excluding id). UpdatePlatformConfigParams.value is relaxed to unknown. Tests in core, command, and API layers were added or adjusted to verify merging, diverse JSON value handling, error cases, and the { data: { name, value } } wire format.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I fetched the old leaves in the night,
Stripped off the tag, then tucked new bites tight,
Numbers or null, each morsel's okay,
Merged and sent tidy—hopping off to play! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: fixing the platform-config update to send the full config payload rather than just the raw value.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/FT-1941/platform-config-update-fix

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/core/platformconfig/platformconfig.test.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

src/core/platformconfig/platformconfig.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.


Comment @coderabbitai help to get the list of available commands and usage tips.

joalves added 2 commits May 30, 2026 14:11
…FT-1941)

The pre-PUT GET in updatePlatformConfig can fail two ways the previous
code mishandled:
- GET throws (404, network, auth): the error reached the user without
  context, looking like a fetch error from an update command.
- GET returns 200 with a non-object payload: surfaced as "existing config
  not found", which actively misled debugging — the real fetch path
  throws on 404, so this branch only fires for malformed responses.

Wrap the GET in try/catch and rethrow with cause, and reword the
non-object branch to name the actual condition. Also document the
last-writer-wins merge semantics inline.
- Rename the not-found test to assert the new malformed-payload wording
  and verify no PUT is attempted.
- Add a test for the GET-rejects path, asserting wrap message and that
  PUT is not attempted.
- Parametrize over falsy JSON values (null, false, 0, "", []) to pin
  the value:unknown contract — a future truthiness guard would regress
  these without the test.
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/core/platformconfig/platformconfig.test.ts (1)

64-83: ⚡ Quick win

Consider adding a beforeEach hook for consistent mock cleanup.

The selective mockClear() calls on lines 66 and 77 are correct (only negative-assertion tests need them), but adding a beforeEach hook to clear all mocks would improve maintainability and prevent future test isolation issues.

♻️ Proposed refactor to add beforeEach hook

Add this after line 9:

   mockClient = {
     listPlatformConfigs: vi.fn(),
     getPlatformConfig: vi.fn(),
     updatePlatformConfig: vi.fn(),
   };
+
+  beforeEach(() => {
+    vi.clearAllMocks();
+  });

Then remove the manual mockClear() calls on lines 66 and 77:

   it('should throw a malformed-payload error if GET returns a non-object', async () => {
     mockClient.getPlatformConfig.mockResolvedValue(null);
-    mockClient.updatePlatformConfig.mockClear();
   it('should wrap GET errors with context and not attempt a PUT', async () => {
     const cause = new Error('network down');
     mockClient.getPlatformConfig.mockRejectedValue(cause);
-    mockClient.updatePlatformConfig.mockClear();
🤖 Prompt for 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.

In `@src/core/platformconfig/platformconfig.test.ts` around lines 64 - 83, Add a
beforeEach hook in the platformconfig.test.ts to call
mockClient.getPlatformConfig.mockClear() and
mockClient.updatePlatformConfig.mockClear() (or jest.clearAllMocks()) so each
test starts with clean mock state, then remove the manual mockClear()
invocations currently inside the two tests that assert negative behavior
(references: mockClient.getPlatformConfig, mockClient.updatePlatformConfig, and
tests invoking updatePlatformConfig).
🤖 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.

Nitpick comments:
In `@src/core/platformconfig/platformconfig.test.ts`:
- Around line 64-83: Add a beforeEach hook in the platformconfig.test.ts to call
mockClient.getPlatformConfig.mockClear() and
mockClient.updatePlatformConfig.mockClear() (or jest.clearAllMocks()) so each
test starts with clean mock state, then remove the manual mockClear()
invocations currently inside the two tests that assert negative behavior
(references: mockClient.getPlatformConfig, mockClient.updatePlatformConfig, and
tests invoking updatePlatformConfig).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6fc30a5f-3e35-47f1-b369-b92064d1ee66

📥 Commits

Reviewing files that changed from the base of the PR and between 038e410 and a6f5176.

📒 Files selected for processing (2)
  • src/core/platformconfig/platformconfig.test.ts
  • src/core/platformconfig/platformconfig.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/core/platformconfig/platformconfig.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant