Repository navigation
core: reject invalid enum members in collection get and subset - #15104
santhiprakash wants to merge 1 commit into
Conversation
The key arguments of collection get and subset take the bare enum input type, which decodes any name without checking the members. A misspelt member therefore reached the key lookup and was reported as a key the collection does not contain. Convert the requested keys through the collection's enum type before the text comparison, the same conversion collectionKeys already applies to stored keys, so a non-member is refused with the usual invalid enum member error that an ordinary argument produces. A valid member that is simply absent from the current subset is still reported missing. Signed-off-by: Santhi Prakash <[email protected]>
19ce13c to
0c9691d
Compare
|
Verified the fix against #15101 locally: checked out this PR at Scope: unit-test level only, I did not run the engine-level repro from #15101. |
|
This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
|
Still relevant — re-checked today: #15101 is open, the requested-key validation added here is still absent from current |
Fixes #15101
Problem
On a collection keyed by an enum,
get(key:)andsubset(keys:)accept anyenum name, whether or not it is a member. A name that isn't a member reaches
the key lookup, and the collection reports it as missing:
Passed to an ordinary argument of the same enum, the same name is refused
correctly:
Root cause
The key arguments take the bare enum input type from
TypeDef.ToInput()(
dagql.EnumValueName), whoseDecodeInputaccepts any string withoutchecking the members.
collectionKeyFromInputthen keeps the caller's textverbatim, so a non-member falls through to the text comparison and produces
the misleading "does not contain key" error. Stored keys already go through
the enum type (
collectionKeys→ModuleEnumType.ConvertFromSDKResult),which is the asymmetry that lets the misspelt name slip through.
Fix
Convert the requested keys through the collection's enum type before the
text comparison, for both
getandsubset. A newcollectionRequestedKeyshelper resolves the enum decoder once per calland checks each requested name with
ModuleEnum.Lookup, so a non-member isrefused with the usual
invalid enum member "Red" for TestColorerror thatan ordinary argument produces. The check uses the member names the schema
exposes (
Local = false), matching how callers spell keys, while storedkeys keep being decoded by their module-original names.
No change to the stored-key path, the valid-key text form,
subsetordering, or the "does not contain key" error for a valid member that is
simply absent from the current subset.
Verification
New unit test
TestCollectionEnumRequestedKeysincore/collection_test.gobuilds an enum-keyed collection (RED/BLUEmembers stored under their original names
ColorRed/ColorBlue) andcovers: stored keys decoding to canonical member names, a valid member
selecting normally, a non-member (
Red) refused withinvalid enum member "Red" for TestColor, a member absent from the currentsubset still reported missing, and non-enum keys converted without a member
check.
With the member check removed the test fails (
An error is expected but got nil), confirming it exercises the new behavior.go build ./core/...andgo vet ./core/are clean;gofmtreports nodiffs.
The full
go test ./core/suite was also run: the only failures areTestNativeWorkspace*/TestGitNative*/TestImportHostCommit*git teststhat require
git init --ref-format=files(host git is 2.43) plus onepack-permission fixture — they fail identically on pristine
mainon thishost and are unrelated to this change.
I could not run the engine-level repro (
dagger api call engine-dev test --pkg ./core/integration --run '^CollectionsSuite/TestEnumKeys$') on thishost — no Dagger engine/Docker available — so the end-to-end path is left
to CI.
Notes
Requested keys are validated against the schema-facing member names
(
Local = false), since callers spellRED, while stored keys decode frommodule-original names (
ColorRed) through the local decoder. Theinvalid enum membererror text is unchanged for the valid-member-missingcase.