-
Notifications
You must be signed in to change notification settings - Fork 11
chore: add rule id to deploydecision and get rules oapi #707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe PR adds a new API endpoint to retrieve a specific policy rule by ID and introduces rule ID tracking in policy evaluation results. Changes span OpenAPI specifications, generated Go bindings, HTTP handlers, and policy evaluation factory to support this new functionality. Changes
Sequence DiagramsequenceDiagram
participant Client as Client
participant Handler as GetRule Handler
participant Workspace as Workspace Store
participant Policy as Policy Lookup
participant Rules as Rules Iteration
Client->>Handler: GET /v1/workspaces/{id}/policies/{id}/rules/{id}
Handler->>Workspace: Fetch workspace by ID
alt Workspace not found
Handler->>Client: 500 Internal Server Error
else Workspace found
Handler->>Policy: Find policy in workspace
alt Policy not found
Handler->>Client: 404 Not Found (policy)
else Policy found
Handler->>Rules: Iterate policy.Rules
alt Matching rule found by ID
rect rgb(200, 220, 240)
note over Rules: Rule matches ruleId parameter
end
Handler->>Client: 200 OK + PolicyRule object
else No matching rule
Handler->>Client: 404 Not Found (rule)
end
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 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 |
📊 DB Package Test Coveragepkg/db coverage: |
📊 Code Coverage Reportworkspace-engine coverage: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
apps/workspace-engine/oapi/openapi.json (1)
3144-3211: New endpoint getRule looks consistent.Parameters and responses mirror existing patterns. Consider adding a tag for grouping (e.g., "Policies") for better client SDK grouping; optional.
apps/workspace-engine/oapi/spec/paths/policy.jsonnet (1)
69-83: Path addition LGTM; add a tag for grouping (optional).Spec reads clean and consistent. If you want SDK grouping, add a "Policies" tag.
Apply this minimal tweak if desired:
'/v1/workspaces/{workspaceId}/policies/{policyId}/rules/{ruleId}': { get: { - summary: 'Get rule', + summary: 'Get rule', + tags: ['Policies'], operationId: 'getRule',Also, confirm openapi.ruleIdParam() exists in ../lib/openapi.libsonnet.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (8)
apps/workspace-engine/oapi/openapi.json(2 hunks)apps/workspace-engine/oapi/spec/lib/openapi.libsonnet(1 hunks)apps/workspace-engine/oapi/spec/paths/policy.jsonnet(1 hunks)apps/workspace-engine/oapi/spec/schemas/policy.jsonnet(1 hunks)apps/workspace-engine/pkg/oapi/evaluation.go(2 hunks)apps/workspace-engine/pkg/oapi/oapi.gen.go(4 hunks)apps/workspace-engine/pkg/server/openapi/policies/policies.go(2 hunks)apps/workspace-engine/pkg/workspace/releasemanager/policy/factory.go(6 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
apps/workspace-engine/**/*.go
📄 CodeRabbit inference engine (apps/workspace-engine/CLAUDE.md)
apps/workspace-engine/**/*.go: Do not add extraneous inline comments that state the obvious
Do not add comments that simply restate what the code does
Do not add comments for standard Go patterns (e.g., noting WaitGroup or semaphore usage)
Write comments that explain why, document complex logic/algorithms, provide non-obvious context, include TODO/FIXME, and document exported functions/types/methods
Files:
apps/workspace-engine/pkg/oapi/evaluation.goapps/workspace-engine/pkg/oapi/oapi.gen.goapps/workspace-engine/pkg/workspace/releasemanager/policy/factory.goapps/workspace-engine/pkg/server/openapi/policies/policies.go
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}
📄 CodeRabbit inference engine (CLAUDE.md)
Formatting: Prettier is used with
@ctrlplane/prettier-config
Files:
apps/workspace-engine/oapi/openapi.json
🧠 Learnings (8)
📓 Common learnings
Learnt from: adityachoudhari26
PR: ctrlplanedev/ctrlplane#637
File: packages/events/src/kafka/client.ts:10-16
Timestamp: 2025-08-01T04:41:41.345Z
Learning: User adityachoudhari26 prefers not to add null safety checks for required environment variables when they are guaranteed to be present in their deployment configuration, similar to their preference for simplicity over defensive programming in test code.
Learnt from: adityachoudhari26
PR: ctrlplanedev/ctrlplane#601
File: e2e/tests/api/policies/retry-policy.spec.ts:23-24
Timestamp: 2025-06-24T23:52:50.732Z
Learning: The user adityachoudhari26 prefers not to add null safety checks or defensive programming in test code, particularly in e2e tests, as they prioritize simplicity and focus on the main functionality being tested rather than comprehensive error handling within the test itself.
📚 Learning: 2025-08-12T18:13:54.630Z
Learnt from: CR
PR: ctrlplanedev/ctrlplane#0
File: apps/workspace-engine/CLAUDE.md:0-0
Timestamp: 2025-08-12T18:13:54.630Z
Learning: Applies to apps/workspace-engine/**/*.go : Write comments that explain why, document complex logic/algorithms, provide non-obvious context, include TODO/FIXME, and document exported functions/types/methods
Applied to files:
apps/workspace-engine/pkg/oapi/oapi.gen.goapps/workspace-engine/pkg/server/openapi/policies/policies.go
📚 Learning: 2025-08-12T18:13:54.630Z
Learnt from: CR
PR: ctrlplanedev/ctrlplane#0
File: apps/workspace-engine/CLAUDE.md:0-0
Timestamp: 2025-08-12T18:13:54.630Z
Learning: Applies to apps/workspace-engine/pkg/model/selector/**/*_test.go : Include edge cases in tests (empty values, special characters, unicode) for condition types
Applied to files:
apps/workspace-engine/pkg/server/openapi/policies/policies.go
📚 Learning: 2025-08-12T18:13:54.630Z
Learnt from: CR
PR: ctrlplanedev/ctrlplane#0
File: apps/workspace-engine/CLAUDE.md:0-0
Timestamp: 2025-08-12T18:13:54.630Z
Learning: Applies to apps/workspace-engine/pkg/model/selector/types.go : Add the new condition type to pkg/model/selector/types.go
Applied to files:
apps/workspace-engine/pkg/server/openapi/policies/policies.go
📚 Learning: 2025-08-12T18:13:54.630Z
Learnt from: CR
PR: ctrlplanedev/ctrlplane#0
File: apps/workspace-engine/CLAUDE.md:0-0
Timestamp: 2025-08-12T18:13:54.630Z
Learning: Applies to apps/workspace-engine/pkg/model/selector/**/*_test.go : Test validation and matching logic separately for condition types
Applied to files:
apps/workspace-engine/pkg/server/openapi/policies/policies.go
📚 Learning: 2025-08-12T18:13:54.630Z
Learnt from: CR
PR: ctrlplanedev/ctrlplane#0
File: apps/workspace-engine/CLAUDE.md:0-0
Timestamp: 2025-08-12T18:13:54.630Z
Learning: Applies to apps/workspace-engine/pkg/model/selector/**/*.go : When adding a new condition type, create a new condition struct in pkg/model/selector implementing the Condition interface
Applied to files:
apps/workspace-engine/pkg/server/openapi/policies/policies.go
📚 Learning: 2025-08-12T18:13:54.630Z
Learnt from: CR
PR: ctrlplanedev/ctrlplane#0
File: apps/workspace-engine/CLAUDE.md:0-0
Timestamp: 2025-08-12T18:13:54.630Z
Learning: Applies to apps/workspace-engine/pkg/model/selector/**/*_test.go : Use table-driven tests for all condition types
Applied to files:
apps/workspace-engine/pkg/server/openapi/policies/policies.go
📚 Learning: 2025-08-12T18:13:54.630Z
Learnt from: CR
PR: ctrlplanedev/ctrlplane#0
File: apps/workspace-engine/CLAUDE.md:0-0
Timestamp: 2025-08-12T18:13:54.630Z
Learning: Applies to apps/workspace-engine/pkg/model/selector/**/*_test.go : Write comprehensive, data-driven tests for new condition types
Applied to files:
apps/workspace-engine/pkg/server/openapi/policies/policies.go
🧬 Code graph analysis (2)
apps/workspace-engine/pkg/oapi/evaluation.go (1)
apps/workspace-engine/pkg/oapi/oapi.gen.go (1)
RuleEvaluation(472-490)
apps/workspace-engine/pkg/server/openapi/policies/policies.go (1)
apps/workspace-engine/pkg/server/openapi/utils/utils.go (1)
GetWorkspace(12-26)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Format
- GitHub Check: Typecheck
- GitHub Check: Lint
- GitHub Check: workspace-engine-tests
- GitHub Check: tests
🔇 Additional comments (6)
apps/workspace-engine/oapi/spec/schemas/policy.jsonnet (1)
140-168: All production code paths properly setruleIdonRuleEvaluationobjects.The factory pattern in
factory.goensures every rule evaluation result is wrapped with.WithRuleId(rule.Id)before being returned (lines 42, 65, 89, 113, 137, 160). All evaluators return single result objects that flow through these factory methods, which then collect them into slices. Thepolicymanager.gouses only these factory methods to retrieve evaluated results, maintaining the contract. Test code createsRuleEvaluationobjects directly for fixtures, which is expected and does not affect production flows.apps/workspace-engine/pkg/oapi/oapi.gen.go (4)
1379-1382: Interface extension looks good; confirm implementers updated.Adding GetRule is fine; ensure all ServerInterface implementers compile.
2335-2375: Wrapper handler LGTM.Param binding and middleware pattern match existing endpoints.
2873-2873: Route registration LGTM.Correct path and wrapper mapping for rules.
487-490: RuleId is consistently populated across all evaluation paths.All six policy evaluation scopes in factory.go (lines 42, 65, 89, 113, 137, 160) follow the same pattern: each evaluator result chains
.WithRuleId(rule.Id)before appending to results. The fluent helper exists, and no code path returns an incomplete RuleEvaluation.apps/workspace-engine/oapi/openapi.json (1)
1140-1148: Adding ruleId (required) is correct; ensure all responses include it.This is an additive-but-required change; any producer omitting ruleId will violate schema. Verify all evaluation results populate it.
Summary by CodeRabbit
Release Notes