Skip to content

Conversation

@rshade
Copy link
Contributor

@rshade rshade commented Oct 16, 2025

Summary

Implemented the EditDependency() option function (Issue #40) that allows upserts of dependencies for the program under test to specific versions. The feature automatically detects the language/build system and modifies the appropriate dependency files.

Supported Languages:

  • Node.js (package.json via npm/yarn)
  • Python (requirements.txt via pip)
  • Go (go.mod via go get)
  • .NET/C# (.csproj files via NuGet)
  • YAML (requires manual configuration)

Implementation Details

New Files

  • pulumitest/opttest/editdependency.go - Option function and DependencyEdit type
  • pulumitest/editdependency.go - Language detection and editing logic for all supported languages
  • pulumitest/editdependency_test.go - Comprehensive unit tests for all language implementations

Modified Files

  • pulumitest/opttest/opttest.go - Added DependencyEdits field to Options struct
  • pulumitest/newStack.go - Added execution logic and warning when used with LocalProviderPath
  • README.md - Added documentation and usage examples
  • CLAUDE.md - Added feature documentation and implementation details

Key Features

  • Automatic Language Detection: Detects Go, Node.js, Python, .NET, and YAML based on file presence
  • Version Specification: Sets exact version for packages in appropriate format per language
  • Conflict Warning: Logs warning when EditDependency is used with LocalProviderPath
  • Error Handling: Provides clear error messages when dependency files are not found or editing fails
  • Consistent API: Follows existing Options pattern like YarnLink and GoModReplacement

Test Coverage

  • 15 unit tests covering:
    • Language detection for all supported languages
    • Editing existing dependencies
    • Adding new dependencies
    • Various dependency file formats (package.json, requirements.txt, .csproj)
    • Error cases (missing files, invalid inputs)

Code Quality

  • Passes golangci-lint v1.64.8 with zero new issues
  • All code follows existing patterns and conventions
  • Proper error handling with descriptive messages
  • Usage of strings.EqualFold for case-insensitive string comparison

Testing

Run tests with:

go test ./pulumitest -v

Run linting with:

~/.local/bin/golangci-lint-versions/golangci-lint run ./...

Usage Example

import (
  "filepath"
  "github.com/pulumi/providertest/pulumitest"
  "github.com/pulumi/providertest/pulumitest/opttest"
)

func TestWithSpecificSDKVersion(t *testing.T) {
  test := pulumitest.NewPulumiTest(t,
    filepath.Join("path", "to", "program"),
    opttest.EditDependency("pulumi", "3.50.0"))
  test.Preview(t)
  test.Up(t)
}

Backward Compatibility

Fully backward compatible. The EditDependency feature is optional and doesn't affect existing code.

Fixes #40

@rshade rshade force-pushed the edit-sdk-dependency branch 5 times, most recently from d6a5da1 to 38bb484 Compare October 27, 2025 19:19
Implemented the `EditDependency()` option function (Issue #40) that allows upserts of dependencies for the program under test to specific versions. The feature automatically detects the language/build system and modifies the appropriate dependency files.

**Supported Languages:**
- Node.js (package.json via npm/yarn)
- Python (requirements.txt via pip)
- Go (go.mod via `go get`)
- .NET/C# (.csproj files via NuGet)
- YAML (requires manual configuration)

- `pulumitest/opttest/editdependency.go` - Option function and DependencyEdit type
- `pulumitest/editdependency.go` - Language detection and editing logic for all supported languages
- `pulumitest/editdependency_test.go` - Comprehensive unit tests for all language implementations

- `pulumitest/opttest/opttest.go` - Added DependencyEdits field to Options struct
- `pulumitest/newStack.go` - Added execution logic and warning when used with LocalProviderPath
- `README.md` - Added documentation and usage examples
- `CLAUDE.md` - Added feature documentation and implementation details

- **Automatic Language Detection**: Detects Go, Node.js, Python, .NET, and YAML based on file presence
- **Version Specification**: Sets exact version for packages in appropriate format per language
- **Conflict Warning**: Logs warning when EditDependency is used with LocalProviderPath
- **Error Handling**: Provides clear error messages when dependency files are not found or editing fails
- **Consistent API**: Follows existing Options pattern like YarnLink and GoModReplacement

- 15 unit tests covering:
  - Language detection for all supported languages
  - Editing existing dependencies
  - Adding new dependencies
  - Various dependency file formats (package.json, requirements.txt, .csproj)
  - Error cases (missing files, invalid inputs)

- Passes golangci-lint v1.64.8 with zero new issues
- All code follows existing patterns and conventions
- Proper error handling with descriptive messages
- Usage of strings.EqualFold for case-insensitive string comparison

Run tests with:
```bash
go test ./pulumitest -v
```

Run linting with:
```bash
~/.local/bin/golangci-lint-versions/golangci-lint run ./...
```

```go
import (
  "filepath"
  "github.com/pulumi/providertest/pulumitest"
  "github.com/pulumi/providertest/pulumitest/opttest"
)

func TestWithSpecificSDKVersion(t *testing.T) {
  test := pulumitest.NewPulumiTest(t,
    filepath.Join("path", "to", "program"),
    opttest.EditDependency("pulumi", "3.50.0"))
  test.Preview(t)
  test.Up(t)
}
```

Fully backward compatible. The EditDependency feature is optional and doesn't affect existing code.

Fixes #40
@rshade rshade force-pushed the edit-sdk-dependency branch from 38bb484 to bdf7c0a Compare November 11, 2025 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Edit SDK dependency

1 participant