Skip to content

Commit f1f89a7

Browse files
patrickerclaude
andcommitted
test: tighten loose assertions found in review
- Unclosed region: use actual unclosed fixture, assert specific error message - Auto-dedent: use 8-space indented fixture, assert code starts at column 0 - allowOutsideRoot: reference file actually outside root, verify both blocked (default) and allowed (with flag) paths Added fixtures: indented.py, unclosed.py Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent da9ce4b commit f1f89a7

3 files changed

Lines changed: 26 additions & 13 deletions

File tree

test/fixtures/snippets/indented.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class TestUsers:
2+
def test_create(self):
3+
# region: create_user
4+
from myapp import client
5+
6+
user = client.create_user(name="Alice")
7+
print(user)
8+
# endregion: create_user
9+
assert user["name"] == "Alice"

test/fixtures/snippets/unclosed.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# region: oops
2+
print("this region is never closed")
3+
print("more code here")

test/plugin.test.mjs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,20 @@ describe('remarkCodeRegion — errors', () => {
8888
});
8989

9090
it('throws on unclosed region', () => {
91-
// Create inline content with an unclosed region
92-
const input = '```python reference="snippets/example.py#nope"\n```';
93-
// (The existing fixture doesn't have unclosed regions, so this just hits "not found")
94-
expect(() => process(input)).toThrow();
91+
const input = '```python reference="snippets/unclosed.py#oops"\n```';
92+
expect(() => process(input)).toThrow('was opened but never closed');
9593
});
9694
});
9795

9896
describe('remarkCodeRegion — auto-dedent', () => {
9997
it('removes common leading whitespace from indented regions', () => {
100-
const input = '```python reference="snippets/example.py#with_asserts"\n```';
98+
const input = '```python reference="snippets/indented.py#create_user"\n```';
10199
const output = process(input);
102-
// The region content is inside a test function (no indent in this fixture,
103-
// but verify dedent doesn't break non-indented code)
104-
expect(output).toContain('result = 2 + 2');
105-
expect(output).not.toMatch(/^ result/m);
100+
// The region is indented 8 spaces in the source (inside class + method).
101+
// After dedent, code should start at column 0.
102+
expect(output).toContain('from myapp import client');
103+
expect(output).not.toMatch(/^ {8}from myapp/m);
104+
expect(output).toMatch(/^from myapp/m);
106105
});
107106
});
108107

@@ -113,11 +112,13 @@ describe('remarkCodeRegion — security', () => {
113112
});
114113

115114
it('allows outside references when allowOutsideRoot is true', () => {
116-
// Reference a file we know exists outside fixtures but inside the project
117-
const input = '```python reference="snippets/example.py#hello"\n```';
118-
// This should work normally (within root)
115+
// Reference a file outside the fixtures root (go up two levels to project README)
116+
const input = '```markdown reference="../../README.md"\n```';
117+
// Without allowOutsideRoot, this would throw
118+
expect(() => process(input)).toThrow('resolves outside the root directory');
119+
// With allowOutsideRoot, it should succeed
119120
const output = process(input, { allowOutsideRoot: true });
120-
expect(output).toContain('name = "World"');
121+
expect(output).toContain('remark-code-region');
121122
});
122123
});
123124

0 commit comments

Comments
 (0)