Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/pull-request-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

jobs:
ci-lint:
runs-on: ubuntu-latest-4cores-16GB

Check failure on line 17 in .github/workflows/pull-request-main.yml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/pull-request-main.yml#L17

label "ubuntu-latest-4cores-16GB" is unknown. available labels are "windows-latest", "windows-latest-8-cores", "windows-2022", "windows-2019", "ubuntu-latest", "ubuntu-latest-4-cores", "ubuntu-latest-8-cores", "ubuntu-latest-16-cores", "ubuntu-24.04", "ubuntu-22.04", "ubuntu-20.04", "macos-latest", "macos-latest-xl", "macos-latest-xlarge", "macos-latest-large", "macos-14-xl", "macos-14-xlarge", "macos-14-large", "macos-14", "macos-14.0", "macos-13-xl", "macos-13-xlarge", "macos-13-large", "macos-13", "macos-13.0", "macos-12-xl", "macos-12-xlarge", "macos-12-large", "macos-12", "macos-12.0", "macos-11", "macos-11.0", "self-hosted", "x64", "arm", "arm64", "linux", "macos", "windows". if it is a custom label for self-hosted runner, set list of labels in actionlint.yaml config file [runner-label]
Raw output
.github/workflows/pull-request-main.yml:17:14: label "ubuntu-latest-4cores-16GB" is unknown. available labels are "windows-latest", "windows-latest-8-cores", "windows-2022", "windows-2019", "ubuntu-latest", "ubuntu-latest-4-cores", "ubuntu-latest-8-cores", "ubuntu-latest-16-cores", "ubuntu-24.04", "ubuntu-22.04", "ubuntu-20.04", "macos-latest", "macos-latest-xl", "macos-latest-xlarge", "macos-latest-large", "macos-14-xl", "macos-14-xlarge", "macos-14-large", "macos-14", "macos-14.0", "macos-13-xl", "macos-13-xlarge", "macos-13-large", "macos-13", "macos-13.0", "macos-12-xl", "macos-12-xlarge", "macos-12-large", "macos-12", "macos-12.0", "macos-11", "macos-11.0", "self-hosted", "x64", "arm", "arm64", "linux", "macos", "windows". if it is a custom label for self-hosted runner, set list of labels in actionlint.yaml config file [runner-label]
permissions:
id-token: write
contents: read
Expand Down Expand Up @@ -43,6 +43,11 @@
contents: read
actions: read
steps:
- name: Install Bun
run: |
curl -fsSL https://bun.sh/install | bash
echo "$HOME/.bun/bin" >> "$GITHUB_PATH"

- name: ci-test
uses: smartcontractkit/.github/actions/ci-test-go@ci-test-go/0.3.5
with:
Expand Down Expand Up @@ -101,7 +106,7 @@
artifact-name: go-test-${{ matrix.os }}

ci-test-system:
runs-on: ubuntu-latest-4cores-16GB

Check failure on line 109 in .github/workflows/pull-request-main.yml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/pull-request-main.yml#L109

label "ubuntu-latest-4cores-16GB" is unknown. available labels are "windows-latest", "windows-latest-8-cores", "windows-2022", "windows-2019", "ubuntu-latest", "ubuntu-latest-4-cores", "ubuntu-latest-8-cores", "ubuntu-latest-16-cores", "ubuntu-24.04", "ubuntu-22.04", "ubuntu-20.04", "macos-latest", "macos-latest-xl", "macos-latest-xlarge", "macos-latest-large", "macos-14-xl", "macos-14-xlarge", "macos-14-large", "macos-14", "macos-14.0", "macos-13-xl", "macos-13-xlarge", "macos-13-large", "macos-13", "macos-13.0", "macos-12-xl", "macos-12-xlarge", "macos-12-large", "macos-12", "macos-12.0", "macos-11", "macos-11.0", "self-hosted", "x64", "arm", "arm64", "linux", "macos", "windows". if it is a custom label for self-hosted runner, set list of labels in actionlint.yaml config file [runner-label]
Raw output
.github/workflows/pull-request-main.yml:109:14: label "ubuntu-latest-4cores-16GB" is unknown. available labels are "windows-latest", "windows-latest-8-cores", "windows-2022", "windows-2019", "ubuntu-latest", "ubuntu-latest-4-cores", "ubuntu-latest-8-cores", "ubuntu-latest-16-cores", "ubuntu-24.04", "ubuntu-22.04", "ubuntu-20.04", "macos-latest", "macos-latest-xl", "macos-latest-xlarge", "macos-latest-large", "macos-14-xl", "macos-14-xlarge", "macos-14-large", "macos-14", "macos-14.0", "macos-13-xl", "macos-13-xlarge", "macos-13-large", "macos-13", "macos-13.0", "macos-12-xl", "macos-12-xlarge", "macos-12-large", "macos-12", "macos-12.0", "macos-11", "macos-11.0", "self-hosted", "x64", "arm", "arm64", "linux", "macos", "windows". if it is a custom label for self-hosted runner, set list of labels in actionlint.yaml config file [runner-label]
if: false # Disable system test untill we have a version of the test that works with the new CRE CLI (Smartcon)
environment: system-test
permissions:
Expand Down
100 changes: 98 additions & 2 deletions cmd/creinit/creinit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package creinit
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"testing"

Expand Down Expand Up @@ -75,6 +76,82 @@ func requireNoDirExists(t *testing.T, dirPath string) {
require.Falsef(t, fi.IsDir(), "directory %s should NOT exist", dirPath)
}

// runLanguageSpecificTests runs the appropriate test suite based on the language field.
// For TypeScript: runs bun install and bun test in the workflow directory.
// For Go: runs go test ./... in the workflow directory.
func runLanguageSpecificTests(t *testing.T, workflowDir, language string) {
t.Helper()

switch language {
case "typescript":
runTypescriptTests(t, workflowDir)
case "go":
runGoTests(t, workflowDir)
default:
t.Logf("Unknown language %q, skipping tests", language)
}
}

// runTypescriptTests executes TypeScript tests using bun.
// Follows the cre init instructions: bun install --cwd <dir> then bun test in that directory.
func runTypescriptTests(t *testing.T, workflowDir string) {
t.Helper()

testFile := filepath.Join(workflowDir, "main.test.ts")
if _, err := os.Stat(testFile); os.IsNotExist(err) {
t.Logf("Skipping TS tests: no main.test.ts in %s", workflowDir)
return
}

t.Logf("Running TypeScript tests in %s", workflowDir)

// Install dependencies using bun install --cwd (as instructed by cre init)
installCmd := exec.Command("bun", "install", "--cwd", workflowDir, "--ignore-scripts")
installOutput, err := installCmd.CombinedOutput()
require.NoError(t, err, "bun install failed in %s:\n%s", workflowDir, string(installOutput))
t.Logf("bun install succeeded")

// Run tests
testCmd := exec.Command("bun", "test")
testCmd.Dir = workflowDir
testOutput, err := testCmd.CombinedOutput()
require.NoError(t, err, "bun test failed in %s:\n%s", workflowDir, string(testOutput))
t.Logf("bun test passed:\n%s", string(testOutput))
}

// runGoTests executes Go tests in the workflow directory.
func runGoTests(t *testing.T, workflowDir string) {
t.Helper()

// Check if there's a go.mod or any .go test files
hasGoTests := false
entries, err := os.ReadDir(workflowDir)
if err != nil {
t.Logf("Skipping Go tests: cannot read %s", workflowDir)
return
}

for _, entry := range entries {
if filepath.Ext(entry.Name()) == "_test.go" {
hasGoTests = true
break
}
}

if !hasGoTests {
t.Logf("Skipping Go tests: no *_test.go files in %s", workflowDir)
return
}

t.Logf("Running Go tests in %s", workflowDir)

testCmd := exec.Command("go", "test", "./...")
testCmd.Dir = workflowDir
testOutput, err := testCmd.CombinedOutput()
require.NoError(t, err, "go test failed in %s:\n%s", workflowDir, string(testOutput))
t.Logf("go test passed:\n%s", string(testOutput))
}

func TestInitExecuteFlows(t *testing.T) {
// All inputs are provided via flags to avoid interactive prompts
cases := []struct {
Expand All @@ -86,6 +163,7 @@ func TestInitExecuteFlows(t *testing.T) {
expectProjectDirRel string
expectWorkflowName string
expectTemplateFiles []string
language string // "go" or "typescript"
}{
{
name: "Go PoR template with all flags",
Expand All @@ -96,6 +174,7 @@ func TestInitExecuteFlows(t *testing.T) {
expectProjectDirRel: "myproj",
expectWorkflowName: "myworkflow",
expectTemplateFiles: GetTemplateFileListGo(),
language: "go",
},
{
name: "Go HelloWorld template with all flags",
Expand All @@ -106,6 +185,7 @@ func TestInitExecuteFlows(t *testing.T) {
expectProjectDirRel: "alpha",
expectWorkflowName: "default-wf",
expectTemplateFiles: GetTemplateFileListGo(),
language: "go",
},
{
name: "Go HelloWorld with different project name",
Expand All @@ -116,6 +196,7 @@ func TestInitExecuteFlows(t *testing.T) {
expectProjectDirRel: "projX",
expectWorkflowName: "workflow-X",
expectTemplateFiles: GetTemplateFileListGo(),
language: "go",
},
{
name: "Go PoR with workflow flag",
Expand All @@ -126,6 +207,7 @@ func TestInitExecuteFlows(t *testing.T) {
expectProjectDirRel: "projFlag",
expectWorkflowName: "flagged-wf",
expectTemplateFiles: GetTemplateFileListGo(),
language: "go",
},
{
name: "Go HelloWorld template by ID",
Expand All @@ -136,6 +218,7 @@ func TestInitExecuteFlows(t *testing.T) {
expectProjectDirRel: "tplProj",
expectWorkflowName: "workflow-Tpl",
expectTemplateFiles: GetTemplateFileListGo(),
language: "go",
},
{
name: "Go PoR template with rpc-url",
Expand All @@ -146,6 +229,7 @@ func TestInitExecuteFlows(t *testing.T) {
expectProjectDirRel: "porWithFlag",
expectWorkflowName: "por-wf-01",
expectTemplateFiles: GetTemplateFileListGo(),
language: "go",
},
{
name: "TS HelloWorld template with rpc-url (ignored)",
Expand All @@ -156,6 +240,18 @@ func TestInitExecuteFlows(t *testing.T) {
expectProjectDirRel: "tsWithRpcFlag",
expectWorkflowName: "ts-wf-flag",
expectTemplateFiles: GetTemplateFileListTS(),
language: "typescript",
},
{
name: "TS PoR template",
projectNameFlag: "tsPorProj",
templateIDFlag: 4, // TypeScript PoR
workflowNameFlag: "ts-por-wf",
rpcURLFlag: "https://sepolia.example/rpc",
expectProjectDirRel: "tsPorProj",
expectWorkflowName: "ts-por-wf",
expectTemplateFiles: GetTemplateFileListTS(),
language: "typescript",
},
}

Expand Down Expand Up @@ -184,8 +280,8 @@ func TestInitExecuteFlows(t *testing.T) {

projectRoot := filepath.Join(tempDir, tc.expectProjectDirRel)
validateInitProjectStructure(t, projectRoot, tc.expectWorkflowName, tc.expectTemplateFiles)
// NOTE: We deliberately don't assert Go/TS scaffolding here because the
// template chosen by prompt could vary; dedicated tests below cover both paths.

runLanguageSpecificTests(t, filepath.Join(projectRoot, tc.expectWorkflowName), tc.language)
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const fetchResult = (sendRequester: ConfidentialHTTPSendRequester, config: Confi
return json(response) as ResponseValues
}

const onCronTrigger = (runtime: Runtime<Config>) => {
export const onCronTrigger = (runtime: Runtime<Config>) => {
runtime.log('Confidential HTTP workflow triggered.')

const confHTTPClient = new ConfidentialHTTPClient()
Expand All @@ -75,7 +75,7 @@ const onCronTrigger = (runtime: Runtime<Config>) => {
}
}

const initWorkflow = (config: Config) => {
export const initWorkflow = (config: Config) => {
const cron = new CronCapability()

return [handler(cron.trigger({ schedule: config.schedule }), onCronTrigger)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"license": "UNLICENSED",
"dependencies": {
"@chainlink/cre-sdk": "^1.0.9",
"@chainlink/cre-sdk": "^1.1.1",
"zod": "3.25.76"
},
"devDependencies": {
Expand Down
Loading
Loading