[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7F57H0JHVN258DZ0E0188FD":3,"skill-same:01M7F57H0JHVN258DZ0E0188FD":43},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":23,"commitSha":24,"skillDirectory":25,"forksCount":13,"repositoryHtmlUrl":26,"repositoryHomepageUrl":6,"ownerHtmlUrl":27,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":28,"install":29,"resources":42},"01M7F57H0JHVN258DZ0E0188FD","testing",null,"How backend code is tested: the external test package, table-driven cases, controller tests with stand-ins, handler tests through Gin, and gateway tests against an in-process server.","workflowaiorg\u002Fworkflow","workflowaiorg","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F344728430?v=4","01M7F5606QN4BXN2KJNCJPCKAZ","01M7F5607RE7Y5NNRN60FW9NJ3",0,"MIT","https:\u002F\u002Fgithub.com\u002Fworkflowaiorg\u002Fworkflow\u002Fblob\u002Fmain\u002Finternal\u002Fcomponent\u002Fbackend\u002Fbase\u002Fskills\u002Ftesting\u002FSKILL.md",[],[],"2026-11-16 10:05:34",false,"---\nname: testing\ndescription: \"How backend code is tested: the external test package, table-driven cases, controller tests with stand-ins, handler tests through Gin, and gateway tests against an in-process server.\"\n---\n\n# Skill: Testing\n\n## When this skill applies\n\n- Writing or changing any Go test\n- Making a stand-in for an interface\n\n## Rules\n\n- **The external test package**: `package orders_test`, never `package orders`. A helper only the\n  tests need goes in `export_test.go`.\n- Beside the code, as `\u003Cfile>_test.go`.\n- **Table-driven** for the cases of one behaviour: `tests := []struct{ name string; … }` and\n  `t.Run(test.name, …)`.\n- `github.com\u002Fstretchr\u002Ftestify`: `require` when the test cannot go on, `assert` otherwise.\n- **No real network, no `os.Setenv`**: build a `Config` literal, use `t.Setenv` when the\n  environment is the thing tested, and `t.Context()` for a context.\n- `go test .\u002F...` runs every test; a test that needs a database or another server says so with a\n  build tag, so the plain run stays fast.\n\n## Stand-ins\n\nAn interface is defined where it is used (the controller defines its `Repository`), so its stand-in\nis small. Write it by hand for an interface of a method or two:\n\n```go\ntype repository struct {\n    order *model.Order\n    err   error\n}\n\nfunc (r repository) StoreOrder(context.Context, model.NewOrder) (*model.Order, error) {\n    return r.order, r.err\n}\n```\n\nFor a larger one, generate it with mockery into a `mocks\u002F` directory beside the interface, and use\nits `mocks.NewXxx(t)`, which checks the expected calls when the test ends.\n\n## A controller test\n\nThe real controller with a stand-in below it: each business rule, and each error from below\npassed on.\n\n## A handler test\n\nThe real handler with a stand-in controller, through Gin. `openapitest.Engine(t)` is `gin.New()`\nthat also checks every response against the service's committed `openapi.yaml`, errors included,\nso a body the contract does not allow fails the test:\n\n```go\nr := openapitest.Engine(t)\nr.POST(\"\u002Forders\", orderhttp.New(controller{order: &model.Order{ID: 7}}).Place)\n\nw := httptest.NewRecorder()\nr.ServeHTTP(w, httptest.NewRequest(http.MethodPost, \"\u002Forders\", strings.NewReader(`{\"customer_id\":1,\"skus\":[\"a\"]}`)))\n\nassert.Equal(t, http.StatusCreated, w.Code)\nassert.JSONEq(t, `{\"data\":{\"order\":{\"id\":7}}}`, w.Body.String())\n```\n\nA test that calls a handler method directly takes its context from `openapitest.Context(t, w)`\ninstead of `gin.CreateTestContext`, and is checked the same way. Assert the whole body with\n`JSONEq`. A handler test that starts failing means the response changed\nshape: find out why before touching the expectation. `api\u002Finternal\u002Fhandler\u002Fhealth\u002Fhttp` has one to\ncopy.\n\n## An HTTP gateway test\n\nAgainst `httptest.NewServer`, never the real service: check the method, path and body the gateway\nsends, and that each error status becomes the right `APIError` code.\n\n## Definition of done\n\n- [ ] Every test file is `package \u003Cpkg>_test`\n- [ ] No test reaches the network or calls `os.Setenv`\n- [ ] Each behaviour's cases are one table\n- [ ] Handler tests serve through `openapitest`, never a bare `gin.New()`\n- [ ] `go test .\u002F...` passes\n","# Skill: Testing\n\n## When this skill applies\n\n- Writing or changing any Go test\n- Making a stand-in for an interface\n\n## Rules\n\n- **The external test package**: `package orders_test`, never `package orders`. A helper only the\n  tests need goes in `export_test.go`.\n- Beside the code, as `\u003Cfile>_test.go`.\n- **Table-driven** for the cases of one behaviour: `tests := []struct{ name string; … }` and\n  `t.Run(test.name, …)`.\n- `github.com\u002Fstretchr\u002Ftestify`: `require` when the test cannot go on, `assert` otherwise.\n- **No real network, no `os.Setenv`**: build a `Config` literal, use `t.Setenv` when the\n  environment is the thing tested, and `t.Context()` for a context.\n- `go test .\u002F...` runs every test; a test that needs a database or another server says so with a\n  build tag, so the plain run stays fast.\n\n## Stand-ins\n\nAn interface is defined where it is used (the controller defines its `Repository`), so its stand-in\nis small. Write it by hand for an interface of a method or two:\n\n```go\ntype repository struct {\n    order *model.Order\n    err   error\n}\n\nfunc (r repository) StoreOrder(context.Context, model.NewOrder) (*model.Order, error) {\n    return r.order, r.err\n}\n```\n\nFor a larger one, generate it with mockery into a `mocks\u002F` directory beside the interface, and use\nits `mocks.NewXxx(t)`, which checks the expected calls when the test ends.\n\n## A controller test\n\nThe real controller with a stand-in below it: each business rule, and each error from below\npassed on.\n\n## A handler test\n\nThe real handler with a stand-in controller, through Gin. `openapitest.Engine(t)` is `gin.New()`\nthat also checks every response against the service's committed `openapi.yaml`, errors included,\nso a body the contract does not allow fails the test:\n\n```go\nr := openapitest.Engine(t)\nr.POST(\"\u002Forders\", orderhttp.New(controller{order: &model.Order{ID: 7}}).Place)\n\nw := httptest.NewRecorder()\nr.ServeHTTP(w, httptest.NewRequest(http.MethodPost, \"\u002Forders\", strings.NewReader(`{\"customer_id\":1,\"skus\":[\"a\"]}`)))\n\nassert.Equal(t, http.StatusCreated, w.Code)\nassert.JSONEq(t, `{\"data\":{\"order\":{\"id\":7}}}`, w.Body.String())\n```\n\nA test that calls a handler method directly takes its context from `openapitest.Context(t, w)`\ninstead of `gin.CreateTestContext`, and is checked the same way. Assert the whole body with\n`JSONEq`. A handler test that starts failing means the response changed\nshape: find out why before touching the expectation. `api\u002Finternal\u002Fhandler\u002Fhealth\u002Fhttp` has one to\ncopy.\n\n## An HTTP gateway test\n\nAgainst `httptest.NewServer`, never the real service: check the method, path and body the gateway\nsends, and that each error status becomes the right `APIError` code.\n\n## Definition of done\n\n- [ ] Every test file is `package \u003Cpkg>_test`\n- [ ] No test reaches the network or calls `os.Setenv`\n- [ ] Each behaviour's cases are one table\n- [ ] Handler tests serve through `openapitest`, never a bare `gin.New()`\n- [ ] `go test .\u002F...` passes\n",{"name":5,"description":7},"main","68fb57dd74de5ed76dcfaff357932684f77650e6","internal\u002Fcomponent\u002Fbackend\u002Fbase\u002Fskills\u002Ftesting","https:\u002F\u002Fgithub.com\u002Fworkflowaiorg\u002Fworkflow","https:\u002F\u002Fgithub.com\u002Fworkflowaiorg","2026-11-13 17:41:05",{"source":8,"skillName":5,"commands":30,"prompt":40,"zipAvailable":41},[31,34,37],{"tool":32,"command":33},"npx","npx skills add workflowaiorg\u002Fworkflow --skill testing",{"tool":35,"command":36},"bunx","bunx skills add workflowaiorg\u002Fworkflow --skill testing",{"tool":38,"command":39},"pnpm","pnpm dlx skills add workflowaiorg\u002Fworkflow --skill testing","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fworkflowaiorg\u002Fworkflow\u002Fblob\u002Fmain\u002Finternal\u002Fcomponent\u002Fbackend\u002Fbase\u002Fskills\u002Ftesting\u002FSKILL.md",true,[],[44,51,58,65,72,77],{"skillNo":45,"name":46,"nameZh":6,"description":47,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":48,"categories":49,"keywords":50,"publishedAt":18},"01M7F58YP2QA8F89599TDWEY0Y","notes","Where notes go.","https:\u002F\u002Fgithub.com\u002Fworkflowaiorg\u002Fworkflow\u002Fblob\u002Fmain\u002Finternal\u002Frender\u002Ftestdata\u002Fsync\u002Fwant\u002F.opencode\u002Fskills\u002Fnotes\u002FSKILL.md",[],[],{"skillNo":52,"name":53,"nameZh":6,"description":54,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":55,"categories":56,"keywords":57,"publishedAt":18},"01M7F58X62078DBFA7YZH0M9VP","naming","How things are named, including the sample's tables.","https:\u002F\u002Fgithub.com\u002Fworkflowaiorg\u002Fworkflow\u002Fblob\u002Fmain\u002Finternal\u002Frender\u002Ftestdata\u002Fsync\u002Fwant\u002F.opencode\u002Fskills\u002Fnaming\u002FSKILL.md",[],[],{"skillNo":59,"name":60,"nameZh":6,"description":61,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":62,"categories":63,"keywords":64,"publishedAt":18},"01M7F58VXX28G09AJCA667GHBS","local","A skill only this project has.","https:\u002F\u002Fgithub.com\u002Fworkflowaiorg\u002Fworkflow\u002Fblob\u002Fmain\u002Finternal\u002Frender\u002Ftestdata\u002Fsync\u002Fwant\u002F.opencode\u002Fskills\u002Flocal\u002FSKILL.md",[],[],{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":18},"01M7F58TQ8XVBD6SDV0S4T6E77","hello","Greets sample's developers.","https:\u002F\u002Fgithub.com\u002Fworkflowaiorg\u002Fworkflow\u002Fblob\u002Fmain\u002Finternal\u002Frender\u002Ftestdata\u002Fsync\u002Fwant\u002F.opencode\u002Fskills\u002Fhello\u002FSKILL.md",[],[],{"skillNo":73,"name":46,"nameZh":6,"description":47,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":18},"01M7F58R379TW8C6VY572RK11F","https:\u002F\u002Fgithub.com\u002Fworkflowaiorg\u002Fworkflow\u002Fblob\u002Fmain\u002Finternal\u002Frender\u002Ftestdata\u002Fsync\u002Fwant\u002F.github\u002Fskills\u002Fnotes\u002FSKILL.md",[],[],{"skillNo":78,"name":53,"nameZh":6,"description":54,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":18},"01M7F58PNRREJ4KPY496M2XHSY","https:\u002F\u002Fgithub.com\u002Fworkflowaiorg\u002Fworkflow\u002Fblob\u002Fmain\u002Finternal\u002Frender\u002Ftestdata\u002Fsync\u002Fwant\u002F.github\u002Fskills\u002Fnaming\u002FSKILL.md",[],[]]