Skip to content

feat: align http request schema with group spec proto JSON representation#3190

Merged
stalniy merged 2 commits into
mainfrom
feat/request-schema
May 18, 2026
Merged

feat: align http request schema with group spec proto JSON representation#3190
stalniy merged 2 commits into
mainfrom
feat/request-schema

Conversation

@stalniy
Copy link
Copy Markdown
Contributor

@stalniy stalniy commented May 18, 2026

Why

Ref CON-347

What

  1. align proto JSON format
  2. fixes units for CPU, they are returned by provider in milicores
  3. removed empty details from the final result

Summary by CodeRabbit

  • New Features

    • Results include an audit status and no longer expose region or 7-day uptime.
    • Resource quantities accept plain or base64-encoded inputs and are normalized to non-negative integers.
  • Refactor

    • CPU, memory, GPU and storage attribute lists are now optional; missing attributes default to empty lists.
    • Exported CPU capacity values are scaled differently (pre-scaling multiplier applied).
  • Bug Fixes

    • Candidate-fetch logging raised to info for clearer observability.
  • Chores

    • Build now runs a type-check step.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

📝 Walkthrough

Walkthrough

Bid-screening schemas across API and provider-inventory apps are updated to validate resource quantities as bigint-transforming strings (supporting both plain unsigned-integer and base64-encoded formats) and make resource attributes optional. Downstream mappers default optional attributes to empty arrays and introduce CPU scaling via a configurable multiplier. The BidScreeningResult type removes region and uptime fields in favor of an isAudited flag, with the service updated accordingly.

Changes

Bid-screening schema and result flow

Layer / File(s) Summary
Bid-screening schema contracts and value transformation
apps/api/src/bid-screening/http-schemas/bid-screening.schema.ts, apps/provider-inventory/src/http-schemas/bid-screening.schema.ts
ResourceValueSchema.val transforms string input (plain unsigned-integer or base64-decoded) to non-negative bigint with max 80-char length. ResourceSchema and StorageResourceSchema make attributes optional for CPU, memory, GPU, and storage; StorageResourceSchema.superRefine uses optional chaining for persistent and class checks.
Request mapping and resource scaling
apps/provider-inventory/src/lib/groupspec-mapper/groupspec-mapper.ts, apps/provider-inventory/src/lib/stream-status-mapper/stream-status-mapper.ts
mapGroupSpecToResourceUnits defaults optional attributes to immutable empty array via nullish coalescing. pairFromSdk accepts optional multiplier parameter; CPU mapping applies 1000n multiplier, scaling allocatable and allocated quantities by 1000x.
Result type and service consumer integration
apps/provider-inventory/src/types/inventory.types.ts, apps/provider-inventory/src/services/bid-screening/bid-screening.service.ts, apps/provider-inventory/src/services/bid-screening/bid-screening.service.spec.ts
BidScreeningResult removes region and uptime7d fields and adds isAudited: boolean. Service mapping removes those fields from result mapping and logs candidates-fetched event at info instead of debug; unit test expectation updated accordingly.
Groupspec mapper tests and fixtures
apps/provider-inventory/src/lib/groupspec-mapper/groupspec-mapper.spec.ts
Fixtures and tests updated to use bigint val values and validate empty-storage behavior; removed invalid-value throwing test.
Stream-status multiplier tests
apps/provider-inventory/src/lib/stream-status-mapper/stream-status-mapper.spec.ts
Added tests exercising parseQuantity multiplier across millicore/core, fractional mantissas, binary SI, negative values, and decimal-exponent inputs.
Build script
apps/provider-inventory/package.json
build now runs tsup and then tsc --noEmit for a compile-time type check.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

size: L

Suggested reviewers

  • baktun14
  • ygrishajev
✨ 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/request-schema

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

@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

❌ Patch coverage is 61.53846% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.24%. Comparing base (956629a) to head (20c2e2c).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...inventory/src/http-schemas/bid-screening.schema.ts 0.00% 4 Missing and 4 partials ⚠️
...c/lib/stream-status-mapper/stream-status-mapper.ts 80.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3190      +/-   ##
==========================================
- Coverage   64.00%   63.24%   -0.77%     
==========================================
  Files        1100     1059      -41     
  Lines       26702    25675    -1027     
  Branches     6468     6306     -162     
==========================================
- Hits        17090    16237     -853     
+ Misses       8413     8249     -164     
+ Partials     1199     1189      -10     
Flag Coverage Δ *Carryforward flag
api 84.27% <ø> (+<0.01%) ⬆️
deploy-web 47.37% <ø> (ø) Carriedforward from 8083857
log-collector ?
notifications 91.06% <ø> (ø) Carriedforward from 8083857
provider-console 81.48% <ø> (ø) Carriedforward from 8083857
provider-inventory 81.85% <61.53%> (-0.45%) ⬇️
provider-proxy 86.08% <ø> (ø) Carriedforward from 8083857
tx-signer ?

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
...ntory/src/lib/groupspec-mapper/groupspec-mapper.ts 100.00% <100.00%> (+10.00%) ⬆️
...rc/services/bid-screening/bid-screening.service.ts 100.00% <100.00%> (ø)
...c/lib/stream-status-mapper/stream-status-mapper.ts 63.15% <80.00%> (ø)
...inventory/src/http-schemas/bid-screening.schema.ts 0.00% <0.00%> (ø)

... and 42 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
apps/provider-inventory/src/http-schemas/bid-screening.schema.ts (1)

99-105: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Response schema/type mismatch: region and uptime7d fields.

Same issue as the API schema. These fields should be removed to match the updated BidScreeningResult type that only includes owner, hostUri, and isAudited.

🤖 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 `@apps/provider-inventory/src/http-schemas/bid-screening.schema.ts` around
lines 99 - 105, ProviderResultSchema currently includes extra fields region and
uptime7d that no longer exist on the BidScreeningResult type; open the
definition of ProviderResultSchema and remove the region and uptime7d properties
so the schema only defines owner, hostUri, and isAudited (preserving their
existing openapi metadata), and ensure any OpenAPI/exports referencing
ProviderResultSchema reflect the reduced shape.
apps/api/src/bid-screening/http-schemas/bid-screening.schema.ts (1)

100-106: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Remove region and uptime7d from ProviderResultSchema.

The schema declares these fields as nullable, but BidScreeningResult and the #toResult() method no longer populate them. This mismatch will cause response validation to fail (if enabled) or OpenAPI documentation to misrepresent actual responses.

🤖 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 `@apps/api/src/bid-screening/http-schemas/bid-screening.schema.ts` around lines
100 - 106, ProviderResultSchema currently declares region and uptime7d but
BidScreeningResult and the BidScreeningResult#toResult() method no longer
populate them; remove the region and uptime7d properties from the
ProviderResultSchema object (and any openapi metadata for them) so the schema
matches the actual responses and OpenAPI output, then run a quick search for
ProviderResultSchema usages to ensure no callers expect those fields and update
any tests/docs that referenced them.
🧹 Nitpick comments (2)
apps/provider-inventory/src/http-schemas/bid-screening.schema.ts (1)

68-68: 💤 Low value

Redundant double .optional()

Same issue as in the API schema—remove the duplicate.

-  endpoints: z.array(z.unknown()).optional().optional()
+  endpoints: z.array(z.unknown()).optional()
🤖 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 `@apps/provider-inventory/src/http-schemas/bid-screening.schema.ts` at line 68,
The "endpoints" property in the schema is calling .optional() twice (endpoints:
z.array(z.unknown()).optional().optional()); remove the redundant second
.optional() so it becomes a single optional call on the z.array(z.unknown()) for
the endpoints field in the bid-screening.schema (look for the endpoints property
in the schema definition).
apps/api/src/bid-screening/http-schemas/bid-screening.schema.ts (1)

69-69: 💤 Low value

Redundant double .optional()

The .optional().optional() chain is redundant—single .optional() suffices.

-  endpoints: z.array(z.unknown()).optional().optional()
+  endpoints: z.array(z.unknown()).optional()
🤖 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 `@apps/api/src/bid-screening/http-schemas/bid-screening.schema.ts` at line 69,
The schema for the "endpoints" property in bid-screening.schema.ts currently
chains .optional() twice on the field definition (endpoints:
z.array(z.unknown()).optional().optional()); remove the redundant second
.optional() so the field reads endpoints: z.array(z.unknown()).optional(),
leaving a single .optional() on the array schema to achieve the intended
optional behavior while keeping the definition clean.
🤖 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.

Outside diff comments:
In `@apps/api/src/bid-screening/http-schemas/bid-screening.schema.ts`:
- Around line 100-106: ProviderResultSchema currently declares region and
uptime7d but BidScreeningResult and the BidScreeningResult#toResult() method no
longer populate them; remove the region and uptime7d properties from the
ProviderResultSchema object (and any openapi metadata for them) so the schema
matches the actual responses and OpenAPI output, then run a quick search for
ProviderResultSchema usages to ensure no callers expect those fields and update
any tests/docs that referenced them.

In `@apps/provider-inventory/src/http-schemas/bid-screening.schema.ts`:
- Around line 99-105: ProviderResultSchema currently includes extra fields
region and uptime7d that no longer exist on the BidScreeningResult type; open
the definition of ProviderResultSchema and remove the region and uptime7d
properties so the schema only defines owner, hostUri, and isAudited (preserving
their existing openapi metadata), and ensure any OpenAPI/exports referencing
ProviderResultSchema reflect the reduced shape.

---

Nitpick comments:
In `@apps/api/src/bid-screening/http-schemas/bid-screening.schema.ts`:
- Line 69: The schema for the "endpoints" property in bid-screening.schema.ts
currently chains .optional() twice on the field definition (endpoints:
z.array(z.unknown()).optional().optional()); remove the redundant second
.optional() so the field reads endpoints: z.array(z.unknown()).optional(),
leaving a single .optional() on the array schema to achieve the intended
optional behavior while keeping the definition clean.

In `@apps/provider-inventory/src/http-schemas/bid-screening.schema.ts`:
- Line 68: The "endpoints" property in the schema is calling .optional() twice
(endpoints: z.array(z.unknown()).optional().optional()); remove the redundant
second .optional() so it becomes a single optional call on the
z.array(z.unknown()) for the endpoints field in the bid-screening.schema (look
for the endpoints property in the schema definition).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 08d31ffa-3ca9-4759-a1ec-c0399c9cbad0

📥 Commits

Reviewing files that changed from the base of the PR and between 956629a and 27424fc.

📒 Files selected for processing (6)
  • apps/api/src/bid-screening/http-schemas/bid-screening.schema.ts
  • apps/provider-inventory/src/http-schemas/bid-screening.schema.ts
  • apps/provider-inventory/src/lib/groupspec-mapper/groupspec-mapper.ts
  • apps/provider-inventory/src/lib/stream-status-mapper/stream-status-mapper.ts
  • apps/provider-inventory/src/services/bid-screening/bid-screening.service.ts
  • apps/provider-inventory/src/types/inventory.types.ts
💤 Files with no reviewable changes (1)
  • apps/provider-inventory/src/types/inventory.types.ts

@stalniy stalniy force-pushed the feat/request-schema branch from 27424fc to e922823 Compare May 18, 2026 12:59
@stalniy stalniy enabled auto-merge May 18, 2026 13:00
Copy link
Copy Markdown
Contributor

@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

🤖 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
`@apps/provider-inventory/src/lib/stream-status-mapper/stream-status-mapper.ts`:
- Around line 69-70: The bug is that CPU scaling (multiplier 1000n) is applied
after parseQuantity truncates fractional values in pairFromSdk, losing millicore
precision; fix by moving the scaling into parseQuantity (or adding a scale
parameter) so the exponent shift happens before integer division/truncation.
Update parseQuantity to accept an optional multiplier (e.g., multiplier = 1n)
and apply it before any integer truncation, then change pairFromSdk to call
parseQuantity(pair?.allocatable, 1000n) and parseQuantity(pair?.allocated,
1000n) (and the analogous call at the other site mentioned) so ResourcePair gets
correctly scaled values without losing fractional millicore precision.
🪄 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: 417b8ed7-c3dd-4b4e-9739-81e70bbcbadf

📥 Commits

Reviewing files that changed from the base of the PR and between 27424fc and e922823.

📒 Files selected for processing (6)
  • apps/api/src/bid-screening/http-schemas/bid-screening.schema.ts
  • apps/provider-inventory/src/http-schemas/bid-screening.schema.ts
  • apps/provider-inventory/src/lib/groupspec-mapper/groupspec-mapper.ts
  • apps/provider-inventory/src/lib/stream-status-mapper/stream-status-mapper.ts
  • apps/provider-inventory/src/services/bid-screening/bid-screening.service.ts
  • apps/provider-inventory/src/types/inventory.types.ts
💤 Files with no reviewable changes (1)
  • apps/provider-inventory/src/types/inventory.types.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • apps/provider-inventory/src/lib/groupspec-mapper/groupspec-mapper.ts
  • apps/provider-inventory/src/services/bid-screening/bid-screening.service.ts
  • apps/provider-inventory/src/http-schemas/bid-screening.schema.ts
  • apps/api/src/bid-screening/http-schemas/bid-screening.schema.ts

Comment thread apps/provider-inventory/src/lib/stream-status-mapper/stream-status-mapper.ts Outdated
@stalniy stalniy force-pushed the feat/request-schema branch from e922823 to 8083857 Compare May 18, 2026 13:06
@github-actions github-actions Bot added size: M and removed size: S labels May 18, 2026
Copy link
Copy Markdown
Contributor

@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 (2)
apps/provider-inventory/src/http-schemas/bid-screening.schema.ts (2)

68-68: 💤 Low value

Redundant .optional().optional() chaining.

The double .optional() has no effect beyond the first call.

-  endpoints: z.array(z.unknown()).optional().optional()
+  endpoints: z.array(z.unknown()).optional()
🤖 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 `@apps/provider-inventory/src/http-schemas/bid-screening.schema.ts` at line 68,
The schema definition for the "endpoints" field in bid-screening.schema.ts is
calling .optional() twice on z.array(z.unknown()) (symbol: endpoints), which is
redundant; remove the duplicate .optional() so the field is declared as
z.array(z.unknown()).optional() to keep intent the same and eliminate the
unnecessary chaining.

9-18: 💤 Low value

NaN as sentinel works but the type predicate is misleading.

The transform returns NaN (a number) on parse failure, then the refine checks typeof val === "bigint". This works but the type annotation (val): val is bigint claims the parameter is already a bigint when it could be NaN. Consider returning null or throwing during transform for clearer semantics, or adjust the type signature.

Cleaner alternative using null sentinel
     .transform(str => {
       if (/^\d+$/.test(str)) return BigInt(str);
       const parsed = Buffer.from(str, "base64").toString("utf-8");
       if (/^\d+$/.test(parsed)) return BigInt(parsed);
-      return NaN;
+      return null;
     })
     .refine(
-      (val): val is bigint => !Number.isFinite(val) && typeof val === "bigint" && val >= 0n,
+      (val): val is bigint => val !== null && val >= 0n,
       "Must be a non-negative integer or its protobuf base64-encoded representation"
     )
🤖 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 `@apps/provider-inventory/src/http-schemas/bid-screening.schema.ts` around
lines 9 - 18, The transform currently returns NaN on parse failure but the
refine type predicate (val): val is bigint is misleading because NaN is a
number; change the transform to return null (or throw) on failure instead of NaN
and update the refine to validate that val is a bigint and non-negative (e.g.,
(val): val is bigint => typeof val === "bigint" && val >= 0n), keeping the same
error message; adjust any downstream code expecting NaN to handle null (or rely
on thrown errors) and ensure the .transform and .refine calls in the
bid-screening.schema (the BigInt/base64 parsing logic) are updated consistently.
🤖 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 `@apps/provider-inventory/src/http-schemas/bid-screening.schema.ts`:
- Line 68: The schema definition for the "endpoints" field in
bid-screening.schema.ts is calling .optional() twice on z.array(z.unknown())
(symbol: endpoints), which is redundant; remove the duplicate .optional() so the
field is declared as z.array(z.unknown()).optional() to keep intent the same and
eliminate the unnecessary chaining.
- Around line 9-18: The transform currently returns NaN on parse failure but the
refine type predicate (val): val is bigint is misleading because NaN is a
number; change the transform to return null (or throw) on failure instead of NaN
and update the refine to validate that val is a bigint and non-negative (e.g.,
(val): val is bigint => typeof val === "bigint" && val >= 0n), keeping the same
error message; adjust any downstream code expecting NaN to handle null (or rely
on thrown errors) and ensure the .transform and .refine calls in the
bid-screening.schema (the BigInt/base64 parsing logic) are updated consistently.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5456d760-42e5-400e-a539-e798804309e2

📥 Commits

Reviewing files that changed from the base of the PR and between 8083857 and 20c2e2c.

📒 Files selected for processing (8)
  • apps/provider-inventory/package.json
  • apps/provider-inventory/src/http-schemas/bid-screening.schema.ts
  • apps/provider-inventory/src/lib/groupspec-mapper/groupspec-mapper.spec.ts
  • apps/provider-inventory/src/lib/groupspec-mapper/groupspec-mapper.ts
  • apps/provider-inventory/src/lib/stream-status-mapper/stream-status-mapper.spec.ts
  • apps/provider-inventory/src/lib/stream-status-mapper/stream-status-mapper.ts
  • apps/provider-inventory/src/services/bid-screening/bid-screening.service.spec.ts
  • apps/provider-inventory/src/types/inventory.types.ts
✅ Files skipped from review due to trivial changes (1)
  • apps/provider-inventory/package.json

@stalniy stalniy added this pull request to the merge queue May 18, 2026
Merged via the queue into main with commit 0ae0146 May 18, 2026
56 checks passed
@stalniy stalniy deleted the feat/request-schema branch May 18, 2026 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants