# Fix CheckImportSource Empty OSS Wildcard

## Analysis

### Impact Table

| Area | File | Change | Verification | Success Criteria |
|------|------|--------|--------------|------------------|
| Premium import OpenAPI response shaping | `internal/openapi/service/importadmin/import_into.go` | Fix OSS wildcard rendering so an empty wildcard remains empty instead of becoming `oss:` | `go test ./internal/openapi/service/importadmin -run 'TestBuild(CheckImportSourceSuccessResp|GetCheckImportSourceTaskSuccessResp)'` | OSS responses return `""` for empty wildcard paths and still return `oss://...` for non-empty paths |
| Sync and async import source checks | `internal/openapi/service/importadmin/import_into.go` | Deduplicate sync `CheckImportSource` result shaping onto the shared helper used by async task polling | `go test ./internal/openapi/service/importadmin -run 'TestBuild(CheckImportSourceSuccessResp|GetCheckImportSourceTaskSuccessResp)'` | Sync and async paths use identical wildcard formatting and empty-dataset handling |
| Regression coverage | `internal/openapi/service/importadmin/import_into_test.go` | Add targeted tests for empty/non-empty OSS wildcard formatting | `go test ./internal/openapi/service/importadmin -run 'TestBuild(CheckImportSourceSuccessResp|GetCheckImportSourceTaskSuccessResp)'` | Tests fail on `oss:` regression and pass once the fix is in place |

### Dead Code / Drift Risk

| Risk | Current State | Planned Mitigation |
|------|---------------|--------------------|
| OSS wildcard formatting drift | Sync `CheckImportSource` has an inline response-building loop while async polling uses `buildCheckImportSourceSuccessResult` | Route sync success response through `buildCheckImportSourceSuccessResp` |
| Empty wildcard mutation | `url.Parse(\"\")` followed by unconditional `Scheme = "oss"` yields `oss:` | Only restore the OSS scheme when the parsed wildcard contains a real URL payload |

### Symbols To Keep / Adjust

Keep:

- `buildCheckImportSourceSuccessResp`
- `buildCheckImportSourceSuccessResult`
- `buildGetCheckImportSourceTaskSuccessResp`
- `(*ImportIntoService).CheckImportSource`

Adjust:

- Add a small helper for formatting wildcard paths consistently across sync and async flows

## Execution Steps

1. Add a shared wildcard-formatting helper for import source check results.
   - Parse the agent wildcard path.
   - Strip query parameters as today.
   - Restore the `oss` scheme only when the parsed URL is non-empty.
   - Verification:
     - `go test ./internal/openapi/service/importadmin -run 'TestBuild(CheckImportSourceSuccessResp|GetCheckImportSourceTaskSuccessResp)'`
     - Expected: empty OSS wildcard stays `""`; non-empty OSS wildcard is `oss://...`.

2. Reuse the shared result builder in sync `CheckImportSource`.
   - Keep request normalization, agent invocation, and transport error handling unchanged.
   - Replace the inline success-shaping logic with `buildCheckImportSourceSuccessResp`.
   - Verification:
     - `go test ./internal/openapi/service/importadmin -run 'TestBuild(CheckImportSourceSuccessResp|GetCheckImportSourceTaskSuccessResp)'`
     - Expected: sync and async responses are shaped identically.

3. Add regression coverage.
   - Cover helper-level empty OSS wildcard behavior.
   - Preserve existing non-empty OSS wildcard behavior.
   - Verify async task response uses the same formatting behavior.
   - Verification:
     - `go test ./internal/openapi/service/importadmin`
     - Expected: package tests pass.

4. Run repo-required Go verification.
   - Verification:
     - `make app-unit-test-local`
     - Expected: command passes without new regressions.

## Risks

- If the “non-empty URL payload” check is too strict, valid OSS wildcards could stop rendering as `oss://...`; tests must cover normal non-empty OSS paths.
- Deduplicating sync response shaping changes the exact control flow in `CheckImportSource`; the transport-error path must stay untouched.

## Assumptions

- This fix belongs under the existing `5090` import-source workstream for execution-plan naming.
- The intended API contract is that an omitted wildcard must round-trip as an empty string regardless of source type.
