Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ coverage/

# Written by functions:serve into the project directory, as V1 did.
logs/
!/src/logs/
!/src/commands/launch/logs/
24 changes: 14 additions & 10 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
fileignoreconfig:
- filename: test/integration/logs-get.test.ts
checksum: 7822d714f476fa4ee588f1b602a7c9e69b8843cc60c09b4ae14cbe4eb2b4ad3b
- filename: src/commands/launch/logs/get.test.ts
checksum: 5ee3d8ba6b014b3a9ac558a750a9a58782bb679d32d30b621e41f977dcc98a0a
- filename: src/core/failure.test.ts
checksum: 242d43885d1e3ef46edf1e347899a90549ebf95ec6827426746852f7a6dfc418
- filename: test/integration/retired-commands.test.ts
checksum: 4f1a3d7b6b6684986f720a44dcd4d4c014a64dd15c41d41d0266afb0ebe828c0
checksum: c38d6e8dae6bd4d2034ff48bff488e89cc00d950a7417c6df890168ac743ae37
- filename: test/integration/manage-base-path.test.ts
checksum: 79eb9ad420ea47d5bee8045d812c45b010bbeeafcaf5f85d11653140b0cd0db1
- filename: src/transport/rest-client.ts
checksum: 755aabbc8ee7a2440d4b696e0c502b612c6a60c50fea38db6537d46849521b41
checksum: 3e44b756be0647422309cb14137bc18f5707cd42de6dd638abd2e0b625fda894
- filename: src/transport/rest-client.test.ts
checksum: 02981226eef6131634d0903fc04fa73a5fb8cac82213f00f49d5f66950d75f8e
checksum: 8f08eb868bb8d608a0d31800c103f7b257f8f414d0fdc6b06ef4ab62acfffd85
- filename: src/transport/cma-client.ts
checksum: 87b8399a9b84ea60fe322802c2e5270772858ba85ac33c436941fe7cf40afc38
- filename: src/transport/auth-strategy.test.ts
Expand All @@ -18,7 +22,7 @@ fileignoreconfig:
- filename: src/projects/projects.api.ts
checksum: 59818dd541577d99c12c50c0c6ef4846ef2db614ab6183cb6dd7b71710931eb1
- filename: src/core/service-context.test.ts
checksum: 7bc4f6ca3ec8a960f84fb4c07453a287bb2bb0ccc7e06c5805a7f56df160024a
checksum: 495972ae75e7ef1b62632c8d099fc589b023976a17d77caaebb049d974edd1bc
- filename: src/core/rules.test.ts
checksum: addfdcffa45491accbc861f28cc2f17528a7e9d77d4c852b302a75cd68d7bdee
- filename: src/core/inputs.test.ts
Expand Down Expand Up @@ -87,7 +91,7 @@ fileignoreconfig:
- "'SECRET=hunter2'"
- "formFieldKey"
- filename: test/integration/projects-create.test.ts
checksum: e37d9a0fdce75f942836f621a2e281cb9b448cd583673ebcacb075de3faaf187
checksum: 4826ca20f0c7fe1f23b82598ceed0a374199e2bb8b604b676efcf720244ff961
- filename: test/fixtures/README.md
checksum: d801c84c8b7d7f38f967573e9a3a70da4405b7cbcbf10d2a6e5be3d65fb3daa1
allowed_patterns:
Expand Down Expand Up @@ -224,12 +228,12 @@ fileignoreconfig:
allowed_patterns:
- "FlagKey"
- filename: src/resources.test.ts
checksum: 742d9faaa855390c853963388bb2479355fe69f0ee05b5a8965de091621d711d
checksum: 05a4c54c69bfff1042fa0df038c46881830e3d7014777c87919c5c0739974f45
allowed_patterns:
- "a project name passed on argv to the project resolver"
- "expect\\(Object.keys\\(DEPENDENCIES\\)\\).toEqual\\(\\['project', 'env'\\]\\)"
- filename: AGENTS.md
checksum: 89b7e72236e7218326eb3c9c3176c5ab36d58e79a9bf845f422fe28d98c144a1
checksum: aafd85677e293bf72dd5764875b202ac3a5531aa083c1c452adaa55021af8c95
allowed_patterns:
- "Do not add an exemption to a guard to make a new file pass"
- "passes its own error wording to `client.request\\(req, MESSAGES\\)`"
Expand All @@ -253,7 +257,7 @@ fileignoreconfig:
- filename: src/git/local-repository.ts
checksum: b9091ed135dfebdf590a5412bbfba2b2f96d4a177cf944a20909b93405268e9f
- filename: test/guards/layering.test.ts
checksum: fea55eeb036ea4acb1cc4d177ae9cbfc1a06bbc5a1ea65b2f5c82717cd0251a9
checksum: fa3a7ee934a03ff88618d02722273ea913b0fc1728d177e86a71d9e69236aa71
- filename: src/commands/launch/projects/create.test.ts
checksum: 9c40b4b6ed4f7d678ecb921a71f5af7284cd685c1337f47144456ae43a38b1ad
- filename: src/commands/launch/projects/delete.test.ts
Expand Down Expand Up @@ -325,7 +329,7 @@ fileignoreconfig:
- filename: src/commands/launch/env/update.test.ts
checksum: 2da219594e7bdd589adc0eff9ff035252a75aaa51dfa20514b18fd3266d7b752
- filename: README.md
checksum: 9c87e9e46dbc9606b4946bb6d84ce36352d8f6d733280f5f48e0a65bd6cf6ded
checksum: 8f1e4d97fa7e97a4c6a3bdb6bbf3d0f4d3735c3dfc23579a4d0a7c6d725bc8e4
allowed_patterns:
- "password-protection"
- "-p, --password"
Expand Down Expand Up @@ -431,7 +435,7 @@ fileignoreconfig:
- filename: test/integration/deployments-create.test.ts
checksum: fd367019e10b47121898440e4b3a54fb2041d6302bee2dea28a97ad58eb88ee9
- filename: src/deployments/deployment.watcher.test.ts
checksum: c2cdab908cba7d4e162d06f59a471f918c959eb9c220ebc3666f0c6299f141b2
checksum: 0a9dab3e2436531279078bb5c0b3ef8524cebf7824b0602b7685ae0b4ef47923
- filename: src/deployments/deployment.create.ts
checksum: ca64f3b29a68c4a2755a88a141e2cd9dbd6fa851a2776876d78c40f3168492e3
- filename: src/commands/launch/deployments/create.test.ts
Expand Down
32 changes: 30 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ src/
core/ the command framework: LaunchCommand, the resolver engine, errors,
exit codes, the core flag catalog (coreFlags), region derivation, the
.cs-launch.json store, and the output primitives
transport/ RestApiClient, the retry policy, auth strategies, proxy detection,
transport/ RestApiClient, EventStreamClient (SSE, event-stream.ts), the one request-header
builder both share, the retry policy, auth strategies, proxy detection,
and LaunchApiError / LaunchNetworkError - no CLI wording lives here
projects/ one resource: repository, value object, domain service, presenter,
error wording, prompt adapter, and the flags it contributes
Expand Down Expand Up @@ -162,6 +163,9 @@ src/
git/ the internal git-namespace / repository / branch lookups
organizations/ the --org flag, its organization picker, and the lookup behind it,
which reads the Contentstack Management API rather than Launch
logs/ logs:get: the server-log window parser and repository, the live log API over SSE, and
the LiveLogFollower that reconnects it; the build-log follow is deployments'. It
reaches deployments only
cache/ the CDN cache purge behind launch:cache:purge: CacheApi, the --path / --prefix / --tags / --hosts
inputs and their normalisation, the criterion prompt and the success lines
site/ the URL choice for an environment's live site (`siteUrlOf`, shared with the deployment follower),
Expand Down Expand Up @@ -491,7 +495,7 @@ promoting these to `src/core/catalog.ts` now.
| 0 | none - oclif exits 0 implicitly | the command did what it was asked to do |
| 1 | `EXIT_RUNTIME` | a runtime failure - `LaunchApiError`, `LaunchNetworkError`, `UnauthenticatedError`, anything oclif handles |
| 2 | `EXIT_USAGE` | a usage error - `UsageError`, `MissingInputError`, a failing cross-flag rule |
| 3 | `EXIT_CANCELLED` | the user declined a confirmation or chose nothing at a picker (`CancelledError`) |
| 3 | `EXIT_CANCELLED` | the user declined a confirmation, chose nothing at a picker (`CancelledError`) or pressed Ctrl-C while the CLI was following a deployment's logs or a live log stream (`logs:get`) |

`launch:functions:serve` is deliberately a plain oclif `Command` rather than a
`LaunchCommand`, because it talks to no API and needs no auth gate, and it is **outside**
Expand Down Expand Up @@ -718,6 +722,30 @@ returning, so the last lines of a build are never lost. The logs are auxiliary:
failed read prints nothing, is retried from the same cursor on the next poll, and never changes the
outcome - the status poll alone decides that.

**The terminal poll drains the logs.** A poll that sees a terminal status does not read the logs once: it keeps
reading from the advancing `tail.since()` until `tail.fresh` returns nothing new, at most `MAX_PAGES` reads, so a
build that wrote more than one page after the last in-flight poll is never cut short. An in-flight poll still makes
exactly one read. A read that fails mid-drain prints nothing, ends the drain and never changes the
outcome. `stop` (an `AbortSignal` on `DeploymentWatchDeps`, `DeploymentFollower.watch(scope, stop)`) ends the wait
with `stop.reason` wherever it is noticed: before a poll, after one, during the drain, and at the sleep - a signal
already aborted when the loop would sleep ends it at once rather than sleeping the full delay, and the default
`sleep` takes the signal as its second argument and clears its timer on abort, so no timer outlives an interrupt.
`onInterrupt(listener)` in `src/core/interruptible-ux.ts` is the one way to hear Ctrl-C around such a wait; like
`cancelOnInterrupt` it detaches in a microtask after the signal, so it is still attached while `signal-exit` looks.

**The live stream is not the watcher.** `logs:get --type live` reads server-sent events, so it sits beside the
polling loop: `EventStreamClient` (`src/transport/event-stream.ts`) is a `node:http`/`node:https` GET (nock can
intercept it; it goes through `proxyRouteFor`) sending `Accept: text/event-stream` - without it the logs service cuts the
request after 14 s. It has an idle timeout (`EVENT_STREAM_IDLE_TIMEOUT_MS`, 30 s) that any received bytes, heartbeats
included, reset, instead of the 60 s request timeout. A 2xx is open; anything else is parsed with `parseErrorEnvelope`
and never retried, except that one 401 gets one `auth.refresh()` and one more request. `LiveLogFollower`
(`src/logs/live-log.follower.ts`) treats a clean end of stream and a retryable `LaunchNetworkError` as a drop and
reconnects after `RetryPolicy.delayFor(n)`; `DEPLOYMENT_MAX_POLL_ERRORS` consecutive drops end it with a
`LaunchNetworkError`, and a connection that delivered any frame starts the count again. `event: session-ended` is the
server's own 5-minute cap: it exits 0 and is never followed by a reconnect. Ctrl-C aborts the same `AbortSignal` the
sleep and the socket listen to, exit 3. The header builder, `buildRequestHeaders` in `rest-client.ts`, is the only place
`X-CS-CLI`, `x-cs-api-version`, the auth headers and the org/project scope headers are assembled.

**Writing a test for it: the fake clock must advance.** `now()` and `sleep()` are injected and both
are required, not optional with defaults. A fake `now: () => 0` with a `sleep` that does nothing
makes the deadline unreachable and the suite **hangs** rather than failing - the same failure mode
Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ with exit code 2 and name their V2 replacements. `launch:functions:serve` is liv
* [`csdx launch:functions`](#csdx-launchfunctions)
* [`csdx launch:functions:serve`](#csdx-launchfunctionsserve)
* [`csdx launch:logs`](#csdx-launchlogs)
* [`csdx launch:logs:get`](#csdx-launchlogsget)
* [`csdx launch:open`](#csdx-launchopen)
* [`csdx launch:projects:create`](#csdx-launchprojectscreate)
* [`csdx launch:projects:delete`](#csdx-launchprojectsdelete)
Expand Down Expand Up @@ -549,6 +550,39 @@ DESCRIPTION

_See code: [src/commands/launch/logs/index.ts](https://github.com/contentstack/launch-cli/blob/v2.0.0-beta.0/src/commands/launch/logs/index.ts)_

## `csdx launch:logs:get`

Read the build or server logs of a deployment of a Launch environment

```
USAGE
$ csdx launch:logs:get [-c <value>] [-d <value>] [--org <value>] [--project <value>] [--env <value>] [--deployment
<value>] [--since <value>] [--until <value>] [--type <value>]

FLAGS
-c, --config=<value> Path to the local '.cs-launch.json' file
-d, --data-dir=<value> Current working directory
--deployment=<value> Deployment UID
--env=<value> Environment name or UID
--org=<value> Organization UID
--project=<value> Project name or UID
--since=<value> Server logs only: start of the window, relative (45s, 30m, 12hr, 2d) or an ISO 8601
timestamp with an offset. Defaults to one hour before --until
--type=<value> Kind of logs to read (deployment | server | live). Defaults to deployment
--until=<value> Server logs only: end of the window, relative (45s, 30m, 12hr, 2d) or an ISO 8601 timestamp
with an offset. Defaults to now

DESCRIPTION
Read the build or server logs of a deployment of a Launch environment

EXAMPLES
$ csdx launch:logs:get --org <org-uid> --project <name-or-uid> --env <name-or-uid>

$ csdx launch:logs:get --org <org-uid> --project <name-or-uid> --env <name-or-uid> --deployment <deployment-uid> --type server --since 2h
```

_See code: [src/commands/launch/logs/get.ts](https://github.com/contentstack/launch-cli/blob/v2.0.0-beta.0/src/commands/launch/logs/get.ts)_

## `csdx launch:open`

Removed in v2 - open the site with launch:site:open
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@
"launch:site": {
"description": "Open the live site of a Launch environment"
},
"launch:logs": {
"description": "Read Launch deployment, server and live logs"
},
"launch:variables": {
"description": "List, set and remove the environment variables of a Launch environment"
},
Expand Down Expand Up @@ -172,6 +175,7 @@
"launch:functions": "LNCH-FN",
"launch:functions:serve": "LNCH-FN-SRV",
"launch:logs": "LNCH-LGS",
"launch:logs:get": "LNCH-LGS-GET",
"launch:open": "LNCH-OPN",
"launch:projects:create": "LNCH-PRJ-CRT",
"launch:projects:delete": "LNCH-PRJ-DEL",
Expand Down
Loading
Loading