Repository navigation
[TST-E4] test: the workspace live tests assert the files' actual contents, read through the containment check - #458
Merged
Conversation
…d through the containment check TST-E4a P01b-1 (U8-17). TestWorkspace gains ReadBytes and ReadTextFile, which resolve through the unchanged ResolvePathBelow, so a rooted, traversal or sibling-prefix path is refused before anything is read. The four live sites in FileSystemClientLiveTests and ProjectsClientLiveTests now assert the exact contents with the path in the expression, where they asserted a true/false ownership predicate. HasBytes, HasTextFile and their contract test stay.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Description
What does this PR do?
It is TST-E4a's U8-17 PR. Four live tests asserted a workspace file's content through a true/false ownership predicate,
workspace.HasTextFile(...).IsTrue()orHasBytes(...).IsTrue(). A failure said only "expected true". They now read the file and assert its exact content, with the path in the expression.TestWorkspace.ReadBytes(relativePath)andReadTextFile(directory, relativePath)resolve through the existing, unchangedResolvePathBelow. A rooted path, a../traversal and a sibling directory that shares the workspace's name prefix are refused before anything is read.The four live sites:
FileSystemClientLiveTests.FindEntriesAsync_And_ListEntriesAsync_Should_Report_The_Workspace_Entries;FileSystemClientLiveTests.WriteFileAsync_Should_Write_Bytes_That_ReadFileAsync_Reads_Back, where the bytes on disk are compared in order;ProjectsClientLiveTests.GetLocationAsync_And_ListProjectsAsync_Should_Report_The_Workspace_Project, with both of its sites.Each keeps the same file and the same expected content.
HasBytes,HasTextFile, their other ownership uses and their contract test are unchanged.New
TestWorkspaceTests: valid nested reads; a read returns the actual (wrong) content rather than a verdict; a missing file propagates; blank inputs refuse with the exact parameter name; and the three escapes refuse on both read APIs. The escapes are seeded with real files outside the workspace, so a read that skipped the containment check would succeed with their content and fail the test.The missing-file test asserts the exact exception type only. Testably's
MockFileSystemleavesFileNotFoundException.FileNameempty, so a path assertion there would be testing the mock, not the workspace.No test method is removed.
PipelineScenario, the other half of this package, follows separately (#448 explains why three of its disposal tests wait).🔄 Type of Change
🎯 Protocol & API Surface
external/,spec/orsrc/was touched🧪 Testing
Test mapping (mechanical:
e4_test_map.pyovergit diff 282a4c1e ac39cfd4)tests/OpenCode.Sdk.Tests/FileSystem/FileSystemClientLiveTests.csFindEntriesAsync_And_ListEntriesAsync_Should_Report_The_Workspace_Entriesin placetests/OpenCode.Sdk.Tests/FileSystem/FileSystemClientLiveTests.csWriteFileAsync_Should_Write_Bytes_That_ReadFileAsync_Reads_Backin placetests/OpenCode.Sdk.Tests/Projects/ProjectsClientLiveTests.csGetLocationAsync_And_ListProjectsAsync_Should_Report_The_Workspace_Projectin placeUnmapped: 0
tests/OpenCode.Sdk.Tests/FileSystem/FileSystemClientLiveTests.cstests/OpenCode.Sdk.Tests/Harness/TestWorkspace.cstests/OpenCode.Sdk.Tests/Harness/TestWorkspaceTests.cstests/OpenCode.Sdk.Tests/Projects/ProjectsClientLiveTests.csThe
TestWorkspaceTestsdelta (+12) is the six new read-contract tests. The three converted live methods keep every assertion they had, and each converted site now asserts exact content.Mutants (each restored byte-identically)
HasBytes/HasTextFilereturn true without reading (base)ReadBytes/ReadTextFilereturn empty content without readingResolvePathBelowand returns the outside file's real contentReadBytesreturns the bytes reversedWriteFileAsync_Should_Write_Bytes_That_ReadFileAsync_Reads_Backis red (index 0: expected 115, got 254).One limit: the Projects test fails at its first converted site, so the "after" mutant does not reach its second site on its own.
Review
ThrowIfNullOrWhiteSpaceon net472.✅ Completion Gate
Local check (
quality-gates.md) on headac39cfd4, base282a4c1e. Every step's own exit code was read:dotnet build --configuration Release: 0 warnings, 0 errorsdotnet format whitespace/dotnet format style --severity warn: no changesverify-clones: passed, 0 new (tests 5.35%); baseline unchangedOpenCode.Sdk.Tools.Tests(all but NativeAot): 2081, 0 failedOpenCode.Sdk.Tests(all but ServiceElection/NativeAot): 8441, 0 failedThe host runs Bun 1.4.3, a maintainer-named off-pin host (
OPENCODE_SDK_TESTS_BUN_MISMATCH=allow); the pin is 1.4.2.✅ Code Quality Checklist
Need help on this PR? Tag
@codesmith-botwith what you need.