diff --git a/agent.codefly.yaml b/agent.codefly.yaml index 30e5f9b..35cb26c 100644 --- a/agent.codefly.yaml +++ b/agent.codefly.yaml @@ -5,3 +5,6 @@ version: 0.0.63 release: owner: workflow workflow: releaser.yml +conformance: + mode: attach-existing-source + fixture: testdata/conformance diff --git a/conformance_test.go b/conformance_test.go new file mode 100644 index 0000000..9dedd9b --- /dev/null +++ b/conformance_test.go @@ -0,0 +1,41 @@ +package main + +import ( + "os" + "os/exec" + "path/filepath" + "testing" + + "github.com/codefly-dev/core/resources" + "github.com/stretchr/testify/require" + "gopkg.in/yaml.v3" +) + +func TestConformanceUsesExistingPythonSource(t *testing.T) { + data, err := os.ReadFile("agent.codefly.yaml") + require.NoError(t, err) + var manifest struct { + Conformance struct { + Mode string `yaml:"mode"` + Fixture string `yaml:"fixture"` + } `yaml:"conformance"` + } + require.NoError(t, yaml.Unmarshal(data, &manifest)) + require.Equal(t, "attach-existing-source", manifest.Conformance.Mode) + require.True(t, filepath.IsLocal(manifest.Conformance.Fixture)) + workspace, err := resources.LoadWorkspaceFromDir(t.Context(), manifest.Conformance.Fixture) + require.NoError(t, err) + module, err := workspace.RootModule(t.Context()) + require.NoError(t, err) + service, err := module.LoadServiceFromName(t.Context(), "subject") + require.NoError(t, err) + require.Equal(t, "codefly.dev", service.Agent.Publisher) + require.Equal(t, "python", service.Agent.Name) + require.Equal(t, "latest", service.Agent.Version, "the isolated release gate must exercise its candidate") + command := exec.CommandContext(t.Context(), "uv", "run", "--frozen", "python", "-m", "unittest", "discover") + command.Dir = filepath.Join(manifest.Conformance.Fixture, "services", "subject", "code") + command.Env = append(os.Environ(), "UV_PROJECT_ENVIRONMENT="+filepath.Join(t.TempDir(), "venv"), "PYTHONDONTWRITEBYTECODE=1") + output, err := command.CombinedOutput() + require.NoError(t, err, string(output)) + require.Contains(t, string(output), "Ran 1 test") +} diff --git a/go.mod b/go.mod index d75bb42..a644659 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.27.0 require ( github.com/codefly-dev/core v0.4.0 github.com/scagogogo/python-requirements-parser v0.0.0-20250717025652-6ca77234c827 + github.com/stretchr/testify v1.12.1 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index 211cb2b..b9fa985 100644 --- a/go.sum +++ b/go.sum @@ -250,8 +250,8 @@ github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC4 github.com/skeema/knownhosts v1.3.2 h1:EDL9mgf4NzwMXCTfaxSD/o/a5fxDw/xL9nkU28JjdBg= github.com/skeema/knownhosts v1.3.2/go.mod h1:bEg3iQAuw+jyiw+484wwFJoKSLwcfd7fqRy+N0QTiow= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/objx v0.5.3 h1:jmXUvGomnU1o3W/V5h2VEradbpJDwGrzugQQvL0POH4= +github.com/stretchr/objx v0.5.3/go.mod h1:rDQraq+vQZU7Fde9LOZLr8Tax6zZvy4kuNKF+QYS+U0= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= diff --git a/testdata/conformance/services/subject/code/.python-version b/testdata/conformance/services/subject/code/.python-version new file mode 100644 index 0000000..e4fba21 --- /dev/null +++ b/testdata/conformance/services/subject/code/.python-version @@ -0,0 +1 @@ +3.12 diff --git a/testdata/conformance/services/subject/code/pyproject.toml b/testdata/conformance/services/subject/code/pyproject.toml new file mode 100644 index 0000000..ba68352 --- /dev/null +++ b/testdata/conformance/services/subject/code/pyproject.toml @@ -0,0 +1,5 @@ +[project] +name = "python-conformance" +version = "0.0.0" +requires-python = ">=3.12" +dependencies = [] diff --git a/testdata/conformance/services/subject/code/test_calculation.py b/testdata/conformance/services/subject/code/test_calculation.py new file mode 100644 index 0000000..f190eb4 --- /dev/null +++ b/testdata/conformance/services/subject/code/test_calculation.py @@ -0,0 +1,6 @@ +import unittest + + +class CalculationTests(unittest.TestCase): + def test_calculation(self): + self.assertEqual(sum([1, 2, 3]), 6) diff --git a/testdata/conformance/services/subject/code/uv.lock b/testdata/conformance/services/subject/code/uv.lock new file mode 100644 index 0000000..ebabd62 --- /dev/null +++ b/testdata/conformance/services/subject/code/uv.lock @@ -0,0 +1,8 @@ +version = 1 +revision = 3 +requires-python = ">=3.12" + +[[package]] +name = "python-conformance" +version = "0.0.0" +source = { virtual = "." } diff --git a/testdata/conformance/services/subject/service.codefly.yaml b/testdata/conformance/services/subject/service.codefly.yaml new file mode 100644 index 0000000..6737fff --- /dev/null +++ b/testdata/conformance/services/subject/service.codefly.yaml @@ -0,0 +1,9 @@ +name: subject +version: 0.0.0 +agent: + kind: codefly:service + publisher: codefly.dev + name: python + version: latest +spec: + source-dir: code diff --git a/testdata/conformance/workspace.codefly.yaml b/testdata/conformance/workspace.codefly.yaml new file mode 100644 index 0000000..e814c85 --- /dev/null +++ b/testdata/conformance/workspace.codefly.yaml @@ -0,0 +1,4 @@ +name: python-conformance +layout: flat +services: + - name: subject