-
Notifications
You must be signed in to change notification settings - Fork 76
feat: add support for pkl files #331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The existing test for ignoring PKL files when the binary is missing was not safe for parallel execution, as it modified a global function variable, creating a data race condition. This commit resolves the issue by refactoring the validation logic: 1. The responsibility for checking for the pkl binary is moved from the CLI into the `PklValidator`. 2. The validator now returns a specific `ErrSkipped` error if the binary is not found. 3. A thread-safe `SetPklBinaryChecker` function is introduced, allowing tests to safely mock the check. 4. The test is updated to use this new thread-safe mechanism.
- Removes a redeclared isPklBinaryPresent function that was causing a build failure. - Updates the test logic to check for the new ErrSkipped sentinel error, aligning it with the recent refactoring. - Removes an unused import.
- Fixes a build failure in the filetype package by using the correct `tools` import. - Updates the `good.pkl` test fixture with valid syntax so that tests pass when the pkl binary is installed.
@akhil-rasheed Thanks for the PR! Please address the issues identified in the unit and mega linter jobs. |
Refactors the pkl validator to improve testability and adds tests for uncovered code paths. - Modifies the `PklValidator` to allow injecting an evaluator factory, making it easier to test error conditions. - Adds a test to verify that `ErrSkipped` is returned when the `pkl` binary is not found. - Adds a test to verify that an error is returned when the pkl evaluator fails to be created.
I've addressed the coverage issues and some whitespace in the workflow file which was causing the yaml linter to fail @kehoecj |
ade80f0
to
309847e
Compare
Still seeing at least one test failure: #331 (comment) |
Removes `t.Parallel()` from tests that modify the global `isPklBinaryPresent` variable. This prevents potential race conditions between tests that rely on the state of this variable.
Resolved |
Can you take another look? I'm still seeing a failure in the pipeline |
This is on the CI, I assume this is where it's failing, but the same test passes for me locally
Am I just not identifying the failure correctly? |
That appears to be the correct failure - let me see if it passes locally for me as well. There may be a timing issue that is present in the pipeline causing it to fail |
I have made the changes that @ccoVeille requested. @kehoecj were you able to replicate the pipeline issue locally? |
Co-authored-by: ccoVeille <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the PKL executable is not installed, a runtime error is generated:
> .\validator.exe .\test\
Warning: 'pkl' binary not found, file C:\Users\se456c\src\github.com\prs\pkl\config-file-validator\test\fixtures\good.pkl will be ignored.
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x7ff78ccb90f0]
goroutine 22 [running]:
github.com/apple/pkl-go/pkl.(*execEvaluator).deinit(0xc000206140)
C:/Users/se456c/go/pkg/mod/github.com/apple/[email protected]/pkl/evaluator_manager_exec.go:214 +0x70
github.com/apple/pkl-go/pkl.(*evaluatorManager).closeErr(0xc000193bc0, {0x7ff78cee41c0?, 0xc000116e80?})
C:/Users/se456c/go/pkg/mod/github.com/apple/[email protected]/pkl/evaluator_manager.go:308 +0x82
github.com/apple/pkl-go/pkl.(*evaluatorManager).listenForImplClose(0xc000193bc0)
C:/Users/se456c/go/pkg/mod/github.com/apple/[email protected]/pkl/evaluator_manager.go:245 +0x46
created by github.com/apple/pkl-go/pkl.NewEvaluatorManagerWithCommand in goroutine 1
C:/Users/se456c/go/pkg/mod/github.com/apple/[email protected]/pkl/evaluator_manager_exec.go:61 +0x256
with: | ||
go-version: "1.25" | ||
|
||
- name: Set up pkl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unit tests shouldn't rely on PKL being present - that should be mocked so the tests are deterministic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok we can do this. But I'll have to extract out the pkl tests to their own function, deviating from the existing pattern of putting tuples in the testData array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine - it's the first time we have to rely on the presence of a local binary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@akhil-rasheed Looking at the PKL Go documentation, I do not think the binary is required anymore. The PKL binary is only required when using code generation and it looks like you can load PKL into a struct without using Code Generation: https://pkl-lang.org/go/current/evaluation.html#without-code-generation. This may only apply to a pre-defined struct though which wouldn't work.
Please take a look and see if this is a viable path. This would greatly simplify the implementation.
Tests are failing with the latest changes due to the runtime error |
Closes #141
Addresses following comments left on the original (abandoned) PR here #164