File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package io
33import (
44 "fmt"
55 "os"
6+ "path/filepath"
67
78 "github.com/alexander-lindner/go-cff"
89 toolspec "github.com/hydrocode-de/tool-spec-go"
@@ -25,6 +26,18 @@ func ReadSpecFile(path string) (toolspec.SpecFile, error) {
2526func ReadInputFile (path string ) (toolspec.InputFile , error ) {
2627 inputBuffer , err := os .ReadFile (path )
2728 if err != nil {
29+ // Backward-compatible fallback for tools that still mount /in/inputs.json.
30+ if os .IsNotExist (err ) && filepath .Base (path ) == "input.json" {
31+ fallbackPath := filepath .Join (filepath .Dir (path ), "inputs.json" )
32+ fallbackBuffer , fallbackErr := os .ReadFile (fallbackPath )
33+ if fallbackErr == nil {
34+ input , parseErr := toolspec .LoadInputs (fallbackBuffer )
35+ if parseErr != nil {
36+ return toolspec.InputFile {}, fmt .Errorf ("failed to load input file: %w" , parseErr )
37+ }
38+ return input , nil
39+ }
40+ }
2841 return toolspec.InputFile {}, fmt .Errorf ("failed to read input file: %w" , err )
2942 }
3043
Original file line number Diff line number Diff line change 1+ package io
2+
3+ import (
4+ "os"
5+ "path/filepath"
6+ "testing"
7+ )
8+
9+ const testInputJSON = `{
10+ "demo": {
11+ "parameters": {},
12+ "data": {}
13+ }
14+ }`
15+
16+ func TestReadInputFileFallsBackToInputsJSON (t * testing.T ) {
17+ dir := t .TempDir ()
18+ fallbackPath := filepath .Join (dir , "inputs.json" )
19+
20+ if err := os .WriteFile (fallbackPath , []byte (testInputJSON ), 0o644 ); err != nil {
21+ t .Fatalf ("failed to write fallback inputs.json: %v" , err )
22+ }
23+
24+ _ , err := ReadInputFile (filepath .Join (dir , "input.json" ))
25+ if err != nil {
26+ t .Fatalf ("expected fallback from input.json to inputs.json, got error: %v" , err )
27+ }
28+ }
29+
30+ func TestReadInputFilePrefersInputJSONWhenPresent (t * testing.T ) {
31+ dir := t .TempDir ()
32+ inputPath := filepath .Join (dir , "input.json" )
33+ fallbackPath := filepath .Join (dir , "inputs.json" )
34+
35+ if err := os .WriteFile (inputPath , []byte (testInputJSON ), 0o644 ); err != nil {
36+ t .Fatalf ("failed to write input.json: %v" , err )
37+ }
38+ if err := os .WriteFile (fallbackPath , []byte ("not-json" ), 0o644 ); err != nil {
39+ t .Fatalf ("failed to write inputs.json: %v" , err )
40+ }
41+
42+ _ , err := ReadInputFile (inputPath )
43+ if err != nil {
44+ t .Fatalf ("expected input.json to be used first, got error: %v" , err )
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments