Files

124 lines
8.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ShortUrl implementation plan
Status: planning only; all feature tasks PLANNED. Baseline
`f1f9ba375b22abf1adcc7c550ec21ac20895c0a4`, inspected 2026-11-24.
Authority: [requirements](../REQUIREMENTS.md) R-004, R-010, R-014–R-016;
[architecture](../ARCHITECTURE.md) C-02–C-05, C-09, C-13.
## Frozen source contract, not a shipped provider
[ShortUrl.hpp](../../../include/Void/ShortUrl/ShortUrl.hpp) declares the EXISTING
`Void::ShortUrl::V1` service, current aliases in `Void::ShortUrl`, service ID
`void.short-url`, version 1, request/result/error types, health and `IShortener`.
`IShortener` derives from Service::IService; resolution defaults to `ErrorCode::unsupported`.
There is no built-in storage or HTTP provider in this module's inventory.
[module.cmake](../../../src/ShortUrl/module.cmake) declares only Service.
[Tests](../../../tests/standalone/ShortUrl/ShortUrl.cpp) exercise a test subclass, identity,
shorten result and optional resolution. This is not a production provider acceptance test.
All three source paths reported matching graph metadata/no recorded issue and were read.
The existing [contract document](../../short-url.md) is preserved. V1 enum ordinals,
member order and virtual order are frozen; same-toolchain C++ ABI restrictions remain.
Nonempty custom keys and nonzero expiry must be honored or rejected as unsupported/conflict.
Zero expiry means permanent; a returned owning provider handle must pin its implementation
for the whole call. The existing header's `unsupported` is the exact error enumerator.
## Completion scope and NEW interfaces
Build native provider logic around injected repository/clock/randomness ports. Keep V1
headers dependent only on Service; optional local and remote provider targets own Storage
and Net dependencies respectively. No external short-link service/account is assumed.
Select the original [Storage](../subsystems/Storage.md) as the first durable local adapter;
an in-memory test adapter establishes semantics but is explicitly nondurable.
```cpp
// NEW illustrative types, outside the frozen V1 interface.
namespace Void::ShortUrl::V2 {
struct ShortenOptions { OperationOptions operation; OperationId id; };
struct Link { std::string key; std::string target_url; Expiry expiry; };
class Provider {
Task<Result<Link>> shorten(CreateLink, ShortenOptions);
Task<Result<Link>> resolve(Key, OperationOptions);
Task<Result<void>> revoke(Key, OperationOptions);
};
}
// NEW LocalProvider composes LinkRepositoryPort, Time clock and Security randomness.
// NEW V1Adapter implements V1::IShortener without adding virtuals or changing layout.
```
Async owns operation options and task lifecycle; Functional owns Result. V2 uses a new
service version/lookup entry, never replaces a V1 provider under an incompatible cast.
The proposed Service C ABI is a separate adapter, not a reinterpretation of V1 objects.
V1Adapter blocks only on an allowed calling thread and maps domain errors to existing
ErrorCode values. It cannot pretend V1 has cooperative cancellation or request identity.
Local create dataflow: validate URL/key/expiry → authorization/rate admission at the host →
generate or validate key → conditional insert plus operation-result record atomically →
durable acknowledgement → construct short URL from configured canonical public base.
Targets accept absolute http/https, no userinfo/control characters; no fetch/preview happens
by default, so create does not contact the target. Host policy can forbid destinations;
if previews are later added, SSRF controls are a separate mandatory capability gate.
Default generated key is 16 base62 characters from rejection-sampled secure randomness;
eight collision retries then conflict/resource error. A custom key is 1–64 ASCII
alphanumerics, '-' or '_', case-sensitive, with reserved route names rejected. Target URL
limit is 8 KiB. Key and target are owned immutable values after admission.
Records contain key, exact target, expiry, revocation flag, creation identity and schema
version. Resolve reads one consistent record: absent → not_found, revoked → revoked,
expired → expired, otherwise return exact stored URL. Expiry is an injected civil instant;
clock-health failures do not extend a link silently. Cleanup is separate from logical expiry.
Revoke creates a tombstone; key reuse is disabled initially so cached old links cannot point
at a new target. V2 idempotency records make retries safe within a configured 24-hour
retention window; expired identities return identity_expired, with no silent retry claim.
RemoteProvider is a NEW generic adapter SPI: explicit origin, secure Net policy, request/
response schema and capability flags. Every provider supplies a conformance fixture;
unsupported custom key/expiry/resolve is reported before network mutation where possible.
Remote errors preserve retry-after and unknown-outcome classification internally; the V1
mapping uses provider_error/unavailable/timeout without fabricating a local rollback.
## Limits and failure matrix
NEW defaults: 128 concurrent operations, 256 waiters, 16 MiB transient budget; remote
responses ≤1 MiB and 10-second total deadline. Local live/tombstone entries have a configured
disk quota, initially 1 GiB, and 10,000 retained V2 operation outcomes; full retention blocks
new creates until cleanup, never drops active identities arbitrarily. Tombstones count toward
quota; reclamation/key reuse requires a later explicit compatibility design. No module-global
worker; managed hosts own cleanup scheduling. Shutdown stops admission and joins storage/network
operations; V1 plugin pins remain held until synchronous calls finish.
| Fault | Required outcome | Gate |
| --- | --- | --- |
| Invalid URL/key/expiry | invalid_request/invalid_url; no mutation | Encoded/control/scheme boundary corpus |
| Custom key collision | conflict, no overwrite | Concurrent conditional inserts |
| Unsupported capability | unsupported, no ignored request fields | Provider conformance matrix |
| Disk/sync failure | storage or unknown commit outcome; inspect/retry by V2 ID | Crash after commit before reply |
| Remote timeout after send | timeout with unknown outcome internally; no blind create replay | Lost response test |
| Expiry/revoke races | Resolve sees a consistent record; no target resurrection | Controlled clock and transaction histories |
| Provider unload during call | Owning Service pin retains generation | Reload during blocked shorten |
| Quota/queue exhausted | rate_limited or resource/unavailable mapping, bounded retention | Full quota plus churn |
## Task DAG
| ID | Phase / dependencies | Scope and acceptance | Recommended role |
| --- | --- | --- | --- |
| M-SHORTURL-01 | P0; baseline | Freeze V1 headers/ABI fixtures and exact semantics; test aliases and default unsupported | sol_implementer |
| M-SHORTURL-02 | P1; M-SHORTURL-01, Service/Functional contracts | NEW V2/domain ports and V1 adapter specification; no V1 layout or method edits | astra_implementer |
| M-SHORTURL-03 | P2; M-SHORTURL-02, Time/Security, Storage conditional batches | Native local provider with durable identity and quota; crash/conflict/expiry tests | sol_implementer |
| M-SHORTURL-04 | P2; M-SHORTURL-02, Net secure/streaming gate | Remote provider SPI and fixture provider; capability and unknown-outcome tests, no shipped external account assumption | sol_implementer |
| M-SHORTURL-05 | P3; M-SHORTURL-03, M-SHORTURL-04, Plugin/Service | Host wiring, metrics and reloadable pins; compatible V1 consumers pass | astra_implementer |
| M-SHORTURL-06 | P4; M-SHORTURL-05, DistributedStorage single-group gate | Optional replicated repository adapter; minority create rejection, committed resolve/revoke history | astra_implementer |
CURRENT checks are linked source tests registered in VoidTests, not rerun here. PROPOSED
provider contract fixtures, process crash points, schema/ABI consumers and reload races
must be added before runner commands are documented. Measure create/resolve p50/p95/p99,
throughput, allocations, RSS/CPU, collision retries, retained records and build cost under
[PERFORMANCE](../PERFORMANCE.md); do not infer provider readiness from interface tests.
Migration leaves V1 and [docs/short-url.md](../../short-url.md) intact. Introduce V2 and
versioned records additively, with V1 mapping tests and explicit data export. Rollback
disables new writes, retains readable old records and provider generations, and never
reuses revoked keys. See [MIGRATION](../MIGRATION.md), [VALIDATION](../VALIDATION.md),
[BUILD-AND-DISTRIBUTION](../BUILD-AND-DISTRIBUTION.md), and
[NetworkedApplications](../platforms/NetworkedApplications.md).