test: cover computeSemanticRules and enforcementPlanner#84
Open
OthmaneZ05 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
NetworkService.computeSemanticRulesis the single source of truth for "can X reach Y": it expands the canvas security groups into pairwise semantic rules, and its output feeds both the real iptables enforcement (EnforcementPlanner→DockerNetworkProvider) and the learning validatorsedge_exists/port_denied. It had no dedicated test; neither didEnforcementPlanner.This PR adds that safety net, with no behaviour change:
networkService.test.ts(34 cases) — default security groups, normalization (protocol casing, missing port/action, ICMP forcing portALL), the ICMP twin ofALL/ALLrules, the threesourceexpansion branches (0.0.0.0/0,subnet-…, node id), nodes not placed in a subnet, ASG replicas (parent-group inheritance, short container ids, running-only expansion, scaled-to-zero fallback), and degenerate configs.DENYprepended by the UI must shadow a later broadALLOW). Reversing the rule iteration incomputeSemanticRulesmakes 15 tests fail.enforcementPlanner.test.ts(7 cases) — 1:1 intent mapping, fail-closed on anything that is not exactlyALLOW, field pass-through, order preserved, terminal zero-trustDENY_ALLalways appended last.virtualNetworkMapper.test.ts(+3 cases) — empty project, already-safe id, and the documented sanitization collision.makeDefaultSgRules,makeNetworkConfig) moved from the learning validators'testSupportto a newmodules/network/testSupport.ts, where the config shape belongs; the learningtestSupportre-exports them, so no validator test changed.Typing, along the way and without touching behaviour: new
SecurityGroupRuleInput/NetworkConfigInputinmodels/networkPolicy.ts, applied to the threeconfig: anyofNetworkService;ValidatorNetworkConfignow extendsNetworkConfigInputinstead of duplicating it withunknown[].dockerNetworkProvider.tsis deliberately left untyped — out of scope here.Types of Changes
Verification & Testing
Automated Checks
npm run lintsuccessfully with no errorsnpm run buildsuccessfully with no compilation errorsnpm testsuccessfully (all tests pass)Manual Verification
npm test(backend): 439 tests / 37 suites green, up from 395.computeSemanticRulesfails 15 of the new cases; reverted.npx jest --config jest.integration.config.js src/modules/network/interSubnet.itest.ts→ 5/5 greennpx jest --config jest.integration.config.js src/modules/learning/engine/engine.itest.ts→ 20/20 greenChecklist