GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — t3code/scripts/notify-discord-release.test.ts at main · SivanTechDev/t3code

Expand file tree

/

notify-discord-release.test.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
174 lines (163 loc) · 5.97 KB
/

notify-discord-release.test.ts

Copy path

File metadata and controls

174 lines (163 loc) · 5.97 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import { assert, it } from "@effect/vitest";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import { HttpClient, HttpClientError, HttpClientResponse } from "effect/unstable/http";
import {
buildDiscordReleaseAnnouncement,
isDiscordReleaseAnnouncementError,
postDiscordWebhook,
} from "./notify-discord-release.ts";
const latestAnnouncement = {
target: "latest",
roleId: "222222222222222222",
releaseName: "T3 Code v1.2.3",
version: "1.2.3",
tag: "v1.2.3",
releaseUrl: new URL("https://github.com/t3dotgg/t3-code/releases/tag/v1.2.3"),
timestamp: "2026-05-01T01:41:00.000Z",
} as const;
const webhookUrl = new URL("https://discord.com/api/webhooks/123456/secret-token");
it("builds a prerelease Discord announcement for nightly subscribers", () => {
assert.deepStrictEqual(
buildDiscordReleaseAnnouncement({
target: "prerelease",
roleId: "111111111111111111",
releaseName: "T3 Code Nightly 1.2.4-nightly.20260501.17 (abcdef123456)",
version: "1.2.4-nightly.20260501.17",
tag: "v1.2.4-nightly.20260501.17",
releaseUrl: new URL(
"https://github.com/t3dotgg/t3-code/releases/tag/v1.2.4-nightly.20260501.17",
),
timestamp: "2026-05-01T01:41:00.000Z",
}),
{
content:
"<@&111111111111111111> Prerelease published: T3 Code Nightly 1.2.4-nightly.20260501.17 (abcdef123456)",
allowed_mentions: {
roles: ["111111111111111111"],
},
embeds: [
{
title: "T3 Code Nightly 1.2.4-nightly.20260501.17 (abcdef123456)",
url: "https://github.com/t3dotgg/t3-code/releases/tag/v1.2.4-nightly.20260501.17",
description: "A new T3 Code prerelease is available for nightly testers.",
color: 0x5865f2,
fields: [
{
name: "Version",
value: "1.2.4-nightly.20260501.17",
inline: true,
},
{
name: "Tag",
value: "v1.2.4-nightly.20260501.17",
inline: true,
},
],
timestamp: "2026-05-01T01:41:00.000Z",
},
],
},
);
});
it("builds a latest Discord announcement for stable subscribers", () => {
assert.deepStrictEqual(buildDiscordReleaseAnnouncement(latestAnnouncement), {
content: "<@&222222222222222222> Latest published: T3 Code v1.2.3",
allowed_mentions: {
roles: ["222222222222222222"],
},
embeds: [
{
title: "T3 Code v1.2.3",
url: "https://github.com/t3dotgg/t3-code/releases/tag/v1.2.3",
description: "A new T3 Code latest release is available.",
color: 0x2ecc71,
fields: [
{
name: "Version",
value: "1.2.3",
inline: true,
},
{
name: "Tag",
value: "v1.2.3",
inline: true,
},
],
timestamp: "2026-05-01T01:41:00.000Z",
},
],
});
});
it.effect("preserves webhook request context and the full client cause chain", () => {
const payload = buildDiscordReleaseAnnouncement(latestAnnouncement);
const requestCause = new Error("request encoder unavailable");
let clientError: HttpClientError.HttpClientError | undefined;
const httpClientLayer = Layer.succeed(
HttpClient.HttpClient,
HttpClient.make((request) => {
clientError = new HttpClientError.HttpClientError({
reason: new HttpClientError.EncodeError({
request,
cause: requestCause,
}),
});
return Effect.fail(clientError);
}),
);
return Effect.gen(function* () {
const error = yield* postDiscordWebhook(webhookUrl, payload, latestAnnouncement).pipe(
Effect.provide(httpClientLayer),
Effect.flip,
);
if (error._tag !== "DiscordReleaseWebhookRequestError") {
assert.fail(`Unexpected error: ${error._tag}`);
}
assert.equal(error.target, "latest");
assert.equal(error.releaseName, latestAnnouncement.releaseName);
assert.equal(error.version, latestAnnouncement.version);
assert.equal(error.tag, latestAnnouncement.tag);
assert.equal(error.releaseUrl, latestAnnouncement.releaseUrl.href);
assert.equal(error.webhookOrigin, webhookUrl.origin);
assert.equal(error.webhookPathnameSegmentCount, 4);
assert.equal(error.contentLength, payload.content.length);
assert.equal(error.embedCount, 1);
assert.equal(error.allowedRoleMentionCount, 1);
assert.equal(error.hasRoleMentionSyntax, true);
assert.equal(error.cause, clientError);
assert.equal((error.cause as HttpClientError.HttpClientError).cause, requestCause);
assert.ok(!error.message.includes(requestCause.message));
assert.equal(isDiscordReleaseAnnouncementError(error), true);
});
});
it.effect("preserves a non-success response error with structured status context", () => {
const payload = buildDiscordReleaseAnnouncement(latestAnnouncement);
const httpClientLayer = Layer.succeed(
HttpClient.HttpClient,
HttpClient.make((request) =>
Effect.succeed(
HttpClientResponse.fromWeb(request, new Response("invalid webhook", { status: 400 })),
),
),
);
return Effect.gen(function* () {
const error = yield* postDiscordWebhook(webhookUrl, payload, latestAnnouncement).pipe(
Effect.provide(httpClientLayer),
Effect.flip,
);
if (error._tag !== "DiscordReleaseWebhookResponseError") {
assert.fail(`Unexpected error: ${error._tag}`);
}
assert.equal(error.target, "latest");
assert.equal(error.tag, latestAnnouncement.tag);
assert.equal(error.webhookOrigin, webhookUrl.origin);
assert.equal(error.webhookPathnameSegmentCount, 4);
assert.equal(error.status, 400);
if (!HttpClientError.isHttpClientError(error.cause)) {
assert.fail("Expected HttpClientError cause");
}
assert.equal(error.cause.reason._tag, "StatusCodeError");
assert.ok(!error.message.includes(error.cause.message));
assert.equal(isDiscordReleaseAnnouncementError(error), true);
});
});
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.