-
Notifications
You must be signed in to change notification settings - Fork 0
Add @total-typescript/shoehorn for type-safe test fixtures #28
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| --- | ||
| name: migrate-to-shoehorn | ||
| description: Migrate test files from `as` type assertions to @total-typescript/shoehorn. Use when user mentions shoehorn, wants to replace `as` in tests, or needs partial test data. | ||
| --- | ||
|
|
||
| # Migrate to Shoehorn | ||
|
|
||
| ## Why shoehorn? | ||
|
|
||
| `shoehorn` lets you pass partial data in tests while keeping TypeScript happy. It replaces `as` assertions with type-safe alternatives. | ||
|
|
||
| **Test code only.** Never use shoehorn in production code. | ||
|
|
||
| Problems with `as` in tests: | ||
|
|
||
| - Trained not to use it | ||
| - Must manually specify target type | ||
| - Double-as (`as unknown as Type`) for intentionally wrong data | ||
|
|
||
| ## Install | ||
|
|
||
| ```bash | ||
| npm i @total-typescript/shoehorn | ||
| ``` | ||
|
|
||
| ## Migration patterns | ||
|
|
||
| ### Large objects with few needed properties | ||
|
|
||
| Before: | ||
|
|
||
| ```ts | ||
| type Request = { | ||
| body: { id: string }; | ||
| headers: Record<string, string>; | ||
| cookies: Record<string, string>; | ||
| // ...20 more properties | ||
| }; | ||
|
|
||
| it("gets user by id", () => { | ||
| // Only care about body.id but must fake entire Request | ||
| getUser({ | ||
| body: { id: "123" }, | ||
| headers: {}, | ||
| cookies: {}, | ||
| // ...fake all 20 properties | ||
| }); | ||
| }); | ||
| ``` | ||
|
|
||
| After: | ||
|
|
||
| ```ts | ||
| import { fromPartial } from "@total-typescript/shoehorn"; | ||
|
|
||
| it("gets user by id", () => { | ||
| getUser( | ||
| fromPartial({ | ||
| body: { id: "123" }, | ||
| }), | ||
| ); | ||
| }); | ||
| ``` | ||
|
|
||
| ### `as Type` → `fromPartial()` | ||
|
|
||
| Before: | ||
|
|
||
| ```ts | ||
| getUser({ body: { id: "123" } } as Request); | ||
| ``` | ||
|
|
||
| After: | ||
|
|
||
| ```ts | ||
| import { fromPartial } from "@total-typescript/shoehorn"; | ||
|
|
||
| getUser(fromPartial({ body: { id: "123" } })); | ||
| ``` | ||
|
|
||
| ### `as unknown as Type` → `fromAny()` | ||
|
|
||
| Before: | ||
|
|
||
| ```ts | ||
| getUser({ body: { id: 123 } } as unknown as Request); // wrong type on purpose | ||
| ``` | ||
|
|
||
| After: | ||
|
|
||
| ```ts | ||
| import { fromAny } from "@total-typescript/shoehorn"; | ||
|
|
||
| getUser(fromAny({ body: { id: 123 } })); | ||
| ``` | ||
|
|
||
| ## When to use each | ||
|
|
||
| | Function | Use case | | ||
| | --------------- | -------------------------------------------------- | | ||
| | `fromPartial()` | Pass partial data that still type-checks | | ||
| | `fromAny()` | Pass intentionally wrong data (keeps autocomplete) | | ||
| | `fromExact()` | Force full object (swap with fromPartial later) | | ||
|
|
||
| ## Workflow | ||
|
|
||
| 1. **Gather requirements** - ask user: | ||
| - What test files have `as` assertions causing problems? | ||
| - Are they dealing with large objects where only some properties matter? | ||
| - Do they need to pass intentionally wrong data for error testing? | ||
|
|
||
| 2. **Install and migrate**: | ||
| - [ ] Install: `npm i @total-typescript/shoehorn` | ||
| - [ ] Find test files with `as` assertions: `grep -r " as [A-Z]" --include="*.test.ts" --include="*.spec.ts"` | ||
| - [ ] Replace `as Type` with `fromPartial()` | ||
| - [ ] Replace `as unknown as Type` with `fromAny()` | ||
| - [ ] Add imports from `@total-typescript/shoehorn` | ||
| - [ ] Run type check to verify | ||
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.
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.
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.
🗄️ Data Integrity & Integration | 🔴 Critical
Fix
skillPathmismatch inskills-lock.json.The
skills-lock.jsonentry formigrate-to-shoehorndeclaresskillPathas"skills/misc/migrate-to-shoehorn/SKILL.md", but this file is actually located at.agents/skills/migrate-to-shoehorn/SKILL.md. This path mismatch means the lock entry does not correctly resolve to the skill documentation. Update theskillPathinskills-lock.jsonto match the actual file location.🧰 Tools
🪛 SkillSpector (2.3.7)
[warning] 99: [MP2] Context Window Stuffing: Skill attempts to fill the context window with filler content, displacing legitimate instructions and safety constraints. This can degrade agent performance or bypass safety boundaries.
Remediation: Implement context-window management that detects and rejects padding or stuffing attempts. Prioritize system instructions over user-injected content.
(Memory Poisoning (MP2))
🤖 Prompt for AI Agents