API and MCP: a call under a workspace alias runs under the workspace
resolve_slug resolves aliases, so /repos/g1t/<repo> and /workspaces/g1t run again under flagon-io, and responses name the workspace by its own slug.
2 files+21−50/2 viewed
| 2982 | 2982 | } | |
| 2983 | 2983 | ||
| 2984 | 2984 | /// Runs the operation. One that found nothing, or was refused, under a | |
| 2985 | − | /// workspace slug that has since been renamed runs again under the | |
| 2986 | − | /// workspace's current slug, and one naming a repository by a path it | |
| 2987 | − | /// was transferred away from runs again at its path now; neither | |
| 2988 | − | /// outcome changed anything. | |
| 2985 | + | /// workspace slug that has since been renamed, or under an alias staff | |
| 2986 | + | /// set, runs again under the workspace's current slug, and one naming a | |
| 2987 | + | /// repository by a path it was transferred away from runs again at its | |
| 2988 | + | /// path now; neither outcome changed anything. | |
| 2989 | 2989 | pub async fn run( | |
| 2990 | 2990 | self, | |
| 2991 | 2991 | services: &Services, |
| 5 | 5 | //! repository (`owner/name`) or a workspace by a slug the workspace has | |
| 6 | 6 | //! since been renamed from is run again under the slug it has now, so | |
| 7 | 7 | //! scripts and agents written against the old address keep working while | |
| 8 | − | //! it redirects. | |
| 8 | + | //! it redirects. A workspace alias g1t's staff set (identity's aliases.rs: | |
| 9 | + | //! `g1t` for `flagon-io`) resolves the same way, for good, so responses | |
| 10 | + | //! name the workspace by its own slug. | |
| 9 | 11 | ||
| 10 | 12 | use g1t_contracts::identity::SlugArgs; | |
| 11 | 13 | use serde_json::Value; | |
| ⋯ | |||
| 107 | 109 | } | |
| 108 | 110 | ||
| 109 | 111 | #[test] | |
| 112 | + | fn an_alias_is_run_again_under_its_workspace() { | |
| 113 | + | let input = json!({ "repo": "g1t/g1t", "number": 7 }); | |
| 114 | + | assert_eq!(named_slug(&input), Some("g1t")); | |
| 115 | + | assert_eq!( | |
| 116 | + | rewrite(&input, "g1t", "flagon-io"), | |
| 117 | + | json!({ "repo": "flagon-io/g1t", "number": 7 }) | |
| 118 | + | ); | |
| 119 | + | assert_eq!( | |
| 120 | + | rewrite(&json!({ "workspace": "G1T" }), "g1t", "flagon-io"), | |
| 121 | + | json!({ "workspace": "flagon-io" }) | |
| 122 | + | ); | |
| 123 | + | } | |
| 124 | + | ||
| 125 | + | #[test] | |
| 110 | 126 | fn rewrites_only_the_old_slug() { | |
| 111 | 127 | let input = json!({ "repo": "Acme/rocket", "workspace": "acme", "title": "acme/x" }); | |
| 112 | 128 | assert_eq!( | |