Skip to content

Updated for likec4 with hmrport config#24

Merged
kieronlanning merged 20 commits into
mainfrom
updated-for-likec4-with-hmrport-config
May 24, 2026
Merged

Updated for likec4 with hmrport config#24
kieronlanning merged 20 commits into
mainfrom
updated-for-likec4-with-hmrport-config

Conversation

@kieronlanning

Copy link
Copy Markdown
Contributor

No description provided.

… cli server

- add --hmr-port arg to container WithArgs callback when HMRPortMode is Configurable (v1.57+)
- add --hmr-port arg to local CLI WithArgs callback when HMR is enabled
- register HMR http endpoint on LikeC4LocalServerResource
- add HMREndpointName and DefaultHMRPort constants to LikeC4LocalServerResource
- add ResolvedHMRPort to ContainerWorkspaceOptions, set from HMRPort option at configure time
- update HMR endpoint targetPort to use resolvedHmrPort so custom HMRPort is respected
- add BuildLocalCLICommand optional hmrPort parameter with spread args helper
- add tests: container args HMR port presence/absence and endpoint target port
- add tests: local CLI HMR endpoint registration and args callback
- add tests: BuildLocalCLICommand with/without hmrPort across all runtimes
…to Windows-only

Console logs from the inner LikeC4ServerResource were never relayed to the
outer AspireC4Resource's Dashboard Console tab. Added ForwardInnerResourceLogsAsync
which subscribes to ResourceLoggerService.WatchAsync on the inner resource and
relays each log line (preserving error/info level) via GetLogger on the outer
resource.

HMR relay analysis: the relay was originally required on all platforms for
pre-v1.57 images (Vite hardcoded HMR to port 24678 but Docker published it on a
random host port). On non-Windows (macOS/Linux) there are no Hyper-V port
reservation issues, so direct fixed-port Docker mapping (24678->24678) has always
been reliable regardless of image version. The relay is only needed on Windows
where Docker Desktop/Hyper-V may reserve port 24678.

Simplify useHmrRelay to OperatingSystem.IsWindows() - removing the FixedPort
condition which was causing non-Windows machines to use the relay unnecessarily
when using the 'latest' image tag (which can't be version-parsed and falls back
to FixedPort mode).
… excludes ParameterResource

- Add HashSet<Type> ExcludedResourceTypes to AspireC4DiagramOptions, defaulting
  to { typeof(ParameterResource) } so passwords/secrets are hidden from diagrams
- Thread excludedResourceTypes through ModelBuilder.Build(), GetVisibleResourceNames(),
  BuildVisibleSet(), and ShouldExclude() using IsAssignableTo() for base-type matching
- Add WithExcludedResourceType<T>() and WithoutExcludedResourceType<T>() fluent
  extension methods on AspireC4DiagramOptions
- Pass opts.ExcludedResourceTypes from lifecycle hook into both FileGeneration and
  DashboardIntegration (WatchResourceStatesAsync) call sites
- Add 13 new unit tests covering default value, fluent mutators, exact and
  base-type exclusion, GetVisibleResourceNames, and null passthrough
When ContainerImageTag is 'latest' (or null) and CheckLatestImageVersion
is true (default), a throwaway container is started at BeforeStartEvent
to run 'likec4 --version'. The resolved version updates HMRPortMode
in ContainerWorkspaceOptions before the WithArgs callback reads it,
ensuring version-gated features (configurable HMR port) work correctly
without pinning a specific tag.

- Add LatestVersionResolver: TryResolveAsync / TryExtractVersion
- Add AspireC4LifecycleHook.LatestVersionResolution partial
- Add CheckLatestImageVersion option (default true) with fluent method
- Add ResolvedLatestContainerVersion / FailedToResolveLatestContainerVersion telemetry
- Add 10 new tests (611 total, 0 failures)
…Resource

When the exact version is known — either from a pinned ContainerImageTag
or resolved via the latest-version check — it is injected as a 'Version'
metadata property on the AspireC4Resource dashboard entry.

The property appears alongside the standard container properties (Image,
Container ID, etc.) in the Aspire dashboard resource details panel.

- Store _resolvedLikeC4Version on the lifecycle hook
- Set from pinned tag at BeforeStartEvent for non-latest tags
- Set from resolved version in TryUpdateHmrPortModeFromLatestVersionAsync
- Inject into ForwardInnerResourceStateAsync property merge
- Remove the conditional guard that prevented _resolvedLikeC4Version from
  being set for the 'latest' tag (the default). The version is now always
  set to at least the effective tag; TryUpdateHmrPortModeFromLatestVersionAsync
  may still overwrite it with the actual resolved version.
- Proactively publish the version property to the outer AspireC4Resource
  at the end of BeforeStartEvent so it appears in the dashboard immediately,
  without waiting for the first inner resource state notification.
- ForwardInnerResourceStateAsync now starts from an empty property set
  instead of forwarding the inner container's raw properties (Container ID,
  etc.), giving the outer resource a clean, user-facing Properties tab that
  contains only the Version.
…RuntimeResolver

Remove the custom env-var-based GetContainerRuntimeExecutable() and replace it
with Aspire 13's IContainerRuntimeResolver (experimental, ASPIRECONTAINERRUNTIME001).

The resolver probes the running container runtime directly (docker/podman in
parallel) and caches the result, so AspireC4 no longer needs to read
ASPIRE_CONTAINER_RUNTIME itself — Aspire handles it the same way.

The two out-of-band subprocess calls (version detection, container-mode
validation) remain because Aspire 13 still has no API for running throwaway
containers. They now use the resolved runtime name from the resolver instead of
the manual env-var check.

Suppress ASPIRECONTAINERRUNTIME001 project-wide with a comment explaining why.
…ainer

Remove all validation infrastructure (ValidateBeforeStart, RunValidationAsync,
GetContainerRuntimeExecutableAsync) since LikeC4 serve already validates DSL.

Replace the ad-hoc docker-run version-detection subprocess with a proper Aspire
one-shot container resource (LikeC4VersionProbeResource) that runs
'likec4 --version' and exits. The lifecycle hook watches its log output via
ResourceLoggerService.WatchAsync and completes a TaskCompletionSource<HMRPortMode>
once a version is parsed. The main server container waits for the probe via
WaitForCompletion, and its WithArgs callback awaits the TCS so the correct
--hmr-port is only added once the version is known.

Changes:
- Remove ValidateBeforeStart option, WithValidateBeforeStart(), RunValidationAsync,
  GetContainerRuntimeExecutableAsync, ContainerBindMountSource, and related telemetry
- Add LikeC4VersionProbeResource (one-shot container, hidden, manifest-excluded)
- Add AspireC4Resource.VersionProbeResource and HMRPortModeTcs properties
- Register TaskCompletionSource<HMRPortMode> as DI singleton; pre-complete when no
  probe is needed (pinned tag or CheckLatestImageVersion disabled)
- WithLocalCLI removes probe resource and pre-completes TCS (fixed port, no detection)
- Delete LatestVersionResolver.TryResolveAsync (entire old subprocess approach)
- Remove NoWarn ASPIRECONTAINERRUNTIME001 (IContainerRuntimeResolver no longer used)
Add LikeC4DslIdAnnotation to override the DSL identifier emitted in the
generated .c4 file without changing the Aspire resource name. Both the
Docker container (LikeC4ServerResource) and the local-CLI executable
(LikeC4LocalServerResource) are now annotated with the parent resource
name (e.g. 'aspirec4') so that they appear as the same element in the
diagram regardless of the '-server' suffix.

Remove IsHidden = true from LikeC4LocalServerResource initial state;
LikeC4 exclusion is controlled exclusively via ExcludeFromLikeC4Annotation.
The hidden state is set at runtime by the lifecycle hook only.

Update extend.c4 -> aspirec4_server reference to -> aspirec4.
Fix Windows/MSYS path expansion in Justfile _e2e-cli-run recipe.
Add PostConfigure<HealthCheckServiceOptions> in WithLocalCLI to remove
the stale container health check after resource removal.
Add unit tests for DSL ID override in ModelBuilder.
Copilot AI review requested due to automatic review settings May 24, 2026 09:43
@kieronlanning kieronlanning enabled auto-merge (squash) May 24, 2026 09:43
@kieronlanning kieronlanning merged commit 9814f40 into main May 24, 2026
3 of 4 checks passed
@kieronlanning kieronlanning deleted the updated-for-likec4-with-hmrport-config branch May 24, 2026 09:45
@kieronlanning kieronlanning removed the request for review from Copilot May 24, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant