Skip to content

fix(cli): summarize nested user/owner fields in -o table (FT-1942)#39

Open
joalves wants to merge 11 commits into
mainfrom
feat/FT-1942/table-user-summary
Open

fix(cli): summarize nested user/owner fields in -o table (FT-1942)#39
joalves wants to merge 11 commits into
mainfrom
feat/FT-1942/table-user-summary

Conversation

@joalves
Copy link
Copy Markdown
Collaborator

@joalves joalves commented May 21, 2026

Summary

  • Replaces the JSON-blob rendering of nested objects in -o table / -o vertical / -o markdown / -o plain with a smart summary: First Last, email, name, title, or the literal [object]. The root cause was formatValue doing JSON.stringify(value) on any nested object, which turned every created_by cell into a 600-char wall of JSON.
  • Adds a summarizeRow to the list commands that previously dumped every API field:
    • apikeys, envs, goaltags, metriccategories, metrictags, roles, tags, units, webhooks
  • Refactors the apps list summariser to reuse the shared formatUserSummary helper.
  • formatOwner in entity-summary.ts now delegates to the same formatUserSummary, so curated row summaries and the default formatter agree.
  • -o json and -o yaml are unchanged (they bypass formatValue entirely). --raw still returns the full untransformed API response for any list command.

JIRA

FT-1942 — CLI: clean up table output for commands that dump user/owner JSON blobs

Before / After

Before (the prompt that motivated this work — apikeys list -o table):

```
│ created_by │
│ {"id":4,"external_id":null,"email":"marcio@absmartly.com","first_name":"Márcio","last_name":"Martins",...} │
```

After:

```
│ created_by │
│ Márcio Martins │
```

Notes for reviewers

  • A subtle behavior tightening in two places: formatOwner and the apps summarizeRow previously treated non-null/non-undefined values as user-shaped. They now require an actual object. In practice the API always returns either a User object or null/missing, so this is safer and not a regression.
  • Date timestamps are passed through as raw ISO strings (consistent with the existing summarizeApiKeyRow / summarizeTagRow style added here, but inconsistent with summarizeGoal/summarizeUserRow which run them through formatDate). Aligning all summarizers on formatDate could be a small follow-up.

Test plan

  • `bun run typecheck` clean
  • `bun run lint` clean
  • `bun run test:run` — 2412 passed, 4 skipped
  • `abs api-keys list -o table --items 3` renders cleanly (10 columns, names not JSON)
  • `abs envs list -o table --items 3` renders cleanly
  • `abs goal-tags list -o table --items 3` renders cleanly
  • `abs metric-categories list -o table --items 3` renders cleanly
  • `abs metric-tags list -o table --items 3` renders cleanly
  • `abs roles list -o table --items 3` renders cleanly
  • `abs tags list -o table --items 3` renders cleanly
  • `abs units list -o table --items 3` renders cleanly
  • `abs webhooks list -o table --items 3` renders cleanly
  • `abs apps list -o table --items 3` still renders cleanly (regression check)
  • `abs api-keys list -o json --items 1 --raw` returns the full unsummarised API object

Summary by CodeRabbit

  • New Features

    • Consistent, condensed row summaries across list commands (environments, API keys, tags, metric categories, roles, units, webhooks, etc.), including formatted created/updated-by values, defaulting for missing fields and archived flags.
    • Object/value summarisation for nested objects: prefers full name, then email, then name/title, otherwise renders as a generic object placeholder.
  • Tests

    • Expanded coverage for summarisation and display formatting, including edge cases and audit-field handling.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c1f396b4-f948-4408-bee7-16b3fcc5963f

📥 Commits

Reviewing files that changed from the base of the PR and between 93bdf9d and 736a492.

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

Walkthrough

This PR establishes object value summarisation utilities and extends entity-row formatting across the CLI's list commands. It introduces formatUserSummary and summarizeObjectValue in the formatter module to extract concise display strings from user and object values, then defines four new row-summariser functions in the entity-summary API (summarizeTagRow, summarizeMetricCategoryRow, summarizeNamedEntityRow, summarizeWebhookRow) that curate entity fields and flatten creator/updater information. These summarisers are then wired into ten list-command configurations (API keys, apps, environments, goal tags, metric categories, metric tags, roles, tags, units, and webhooks), with corresponding test updates to verify the richer output shapes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • absmartly/cli-ts#2: Introduces the entity-summary foundation and related user-formatting utilities that form the base for this PR's extension of summarisation helpers across multiple commands.

Poem

🐰 A formatter's craft, now refined and true,
Object values summarised in graceful view—
Row after row, the list commands now sing,
With curated fields and audit fields that ring!

🚥 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 accurately summarizes the main change: fixing nested user/owner field summarization in table output format, which is the core objective of this pull request.
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-1942/table-user-summary
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch feat/FT-1942/table-user-summary

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/commands/apikeys/apikeys.test.ts

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

src/commands/apps/apps.test.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.

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/commands/apps/apps.test.ts (1)

56-59: ⚡ Quick win

Add coverage for created_by summarisation in the list assertion.

This matcher now only checks id/name, so the new created_by formatting path can regress unnoticed.

Suggested test tightening
-  const mockClient = {
-    listApplications: vi.fn().mockResolvedValue([{ id: 1, name: 'web' }]),
+  const mockClient = {
+    listApplications: vi.fn().mockResolvedValue([
+      {
+        id: 1,
+        name: 'web',
+        created_by: { first_name: 'Ada', last_name: 'Lovelace', email: 'ada@example.com' },
+      },
+    ]),
@@
-    expect(printFormatted).toHaveBeenCalledWith(
-      [expect.objectContaining({ id: 1, name: 'web' })],
-      expect.anything()
-    );
+    expect(printFormatted).toHaveBeenCalledWith(
+      [expect.objectContaining({ id: 1, name: 'web', created_by: 'Ada Lovelace' })],
+      expect.anything()
+    );
🤖 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/commands/apps/apps.test.ts` around lines 56 - 59, Update the test
assertion in apps.test.ts that checks printFormatted to also assert the
created_by summarisation is present and correctly formatted: locate the
expect(printFormatted).toHaveBeenCalledWith(...) assertion and extend the
expect.objectContaining payload for the app entry (id: 1, name: 'web') to
include a created_by property check (use a matcher like expect.stringMatching or
expect.any(String) with a regex that matches the expected summary format) so the
test will fail if the created_by formatting path regresses.
🤖 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 `@src/commands/apikeys/apikeys.test.ts`:
- Line 115: The test contains a secret-like literal assigned to hashed_key which
can trigger leak scanners; replace the real-looking value in the test (the
hashed_key string in src/commands/apikeys/apikeys.test.ts) with an obviously
synthetic placeholder (e.g., "FAKE_HASHED_KEY_PLACEHOLDER" or similar) so it no
longer resembles a real credential; update any assertions or fixtures that
reference this exact value to use the new placeholder constant to keep tests
consistent.

---

Nitpick comments:
In `@src/commands/apps/apps.test.ts`:
- Around line 56-59: Update the test assertion in apps.test.ts that checks
printFormatted to also assert the created_by summarisation is present and
correctly formatted: locate the expect(printFormatted).toHaveBeenCalledWith(...)
assertion and extend the expect.objectContaining payload for the app entry (id:
1, name: 'web') to include a created_by property check (use a matcher like
expect.stringMatching or expect.any(String) with a regex that matches the
expected summary format) so the test will fail if the created_by formatting path
regresses.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 85e72daf-eeca-4159-b453-93891ba52240

📥 Commits

Reviewing files that changed from the base of the PR and between 690880f and 93bdf9d.

📒 Files selected for processing (19)
  • src/api-client/entity-summary.test.ts
  • src/api-client/entity-summary.ts
  • src/commands/apikeys/apikeys.test.ts
  • src/commands/apikeys/index.ts
  • src/commands/apps/apps.test.ts
  • src/commands/apps/index.ts
  • src/commands/envs/envs.test.ts
  • src/commands/envs/index.ts
  • src/commands/goaltags/index.ts
  • src/commands/metriccategories/index.ts
  • src/commands/metrictags/index.ts
  • src/commands/roles/index.ts
  • src/commands/roles/roles.test.ts
  • src/commands/tags/index.ts
  • src/commands/units/index.ts
  • src/commands/units/units.test.ts
  • src/commands/webhooks/index.ts
  • src/lib/output/formatter.test.ts
  • src/lib/output/formatter.ts

Comment thread src/commands/apikeys/apikeys.test.ts Outdated
- replace secret-like hashed_key literal with synthetic placeholder
- assert created_by summarisation in apps list test
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