@@ -96,6 +96,55 @@ func TestRuntimeHonorsTypedSelectionWithDefaultRunner(t *testing.T) {
9696 assertRuntimeTestLeftSourceClean (t , dir )
9797}
9898
99+ // TestRuntimeTypedSelectionReplacesBroadPytestDiscovery proves that the exact
100+ // semantic selector is the whole collection scope. The project formula is
101+ // intentionally broad and contains an unrelated collection crash; retaining
102+ // that operand would produce a false red result even though the selected case
103+ // passes. Real uv + pytest exercise the production boundary without mocks.
104+ func TestRuntimeTypedSelectionReplacesBroadPytestDiscovery (t * testing.T ) {
105+ if _ , err := exec .LookPath ("uv" ); err != nil {
106+ t .Fatalf ("uv is required for the production Python runtime: %v" , err )
107+ }
108+ root := t .TempDir ()
109+ if err := os .MkdirAll (filepath .Join (root , "broadpkg" ), 0o755 ); err != nil {
110+ t .Fatal (err )
111+ }
112+ for path , content := range map [string ]string {
113+ "tox.ini" : `[testenv]
114+ commands = pytest --pyargs broadpkg {posargs}
115+ ` ,
116+ "broadpkg/__init__.py" : "" ,
117+ "broadpkg/test_broken.py" : "raise RuntimeError('unselected collection must not run')\n " ,
118+ "test_selected.py" : "def test_selected_pass():\n assert 2 + 2 == 4\n " ,
119+ } {
120+ if err := os .WriteFile (filepath .Join (root , filepath .FromSlash (path )), []byte (content ), 0o644 ); err != nil {
121+ t .Fatal (err )
122+ }
123+ }
124+
125+ svc := pythonservice .New (& resources.Agent {Kind : "codefly:service" , Name : "python" })
126+ svc .SourceLocation = root
127+ rt := pythonruntime .New (svc )
128+ req := & runtimev0.TestRequest {
129+ Selection : & runtimev0.TestSelection {Scope : & runtimev0.TestSelection_TestCase {TestCase : & runtimev0.TestCaseSelection {
130+ Path : "test_selected.py" ,
131+ QualifiedName : []string {"test_selected_pass" },
132+ }}},
133+ SelectionId : "formula-exact-python-selected-case" ,
134+ }
135+ resp , err := rt .Test (context .Background (), req )
136+ if err != nil {
137+ t .Fatalf ("Test: %v" , err )
138+ }
139+ if err := selectioncontract .VerifyAcknowledgement (req , resp ); err != nil {
140+ t .Fatalf ("selection acknowledgement: %v" , err )
141+ }
142+ if resp .GetResult ().GetState () != runtimev0 .TestRunResult_PASSED || resp .GetCounts ().GetTotal () != 1 || resp .GetCounts ().GetPassed () != 1 {
143+ t .Fatalf ("selected result = %s counts=%+v, want only one passing case\n %s" , resp .GetResult ().GetState (), resp .GetCounts (), resp .GetOutput ())
144+ }
145+ assertRuntimeTestLeftSourceClean (t , root )
146+ }
147+
99148// TestRuntimeFormulaNormalizesUnittestDisplaySelection proves the production
100149// agent boundary accepts the canonical case identity returned by unittest
101150// (`method (module.Class)`) and routes it back through a formula that consumes
0 commit comments