agent-messenger 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/commands/release.md +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.github/workflows/ci.yml +1 -1
- package/.github/workflows/e2e.yml.disabled +69 -0
- package/README.md +16 -14
- package/biome.json +33 -1
- package/bun.lock +63 -0
- package/dist/package.json +8 -4
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +4 -1
- package/dist/src/cli.js.map +1 -1
- package/dist/src/platforms/discord/cli.js +1 -1
- package/dist/src/platforms/discord/client.d.ts.map +1 -1
- package/dist/src/platforms/discord/client.js +3 -3
- package/dist/src/platforms/discord/client.js.map +1 -1
- package/dist/src/platforms/discord/commands/user.d.ts.map +1 -1
- package/dist/src/platforms/discord/commands/user.js +10 -1
- package/dist/src/platforms/discord/commands/user.js.map +1 -1
- package/dist/src/platforms/discord/credential-manager.d.ts.map +1 -1
- package/dist/src/platforms/discord/credential-manager.js +18 -12
- package/dist/src/platforms/discord/credential-manager.js.map +1 -1
- package/dist/src/platforms/slack/cli.js +1 -1
- package/dist/src/platforms/slack/credential-manager.d.ts.map +1 -1
- package/dist/src/platforms/slack/credential-manager.js +20 -6
- package/dist/src/platforms/slack/credential-manager.js.map +1 -1
- package/dist/src/platforms/slack/token-extractor.d.ts.map +1 -1
- package/dist/src/platforms/slack/token-extractor.js +34 -9
- package/dist/src/platforms/slack/token-extractor.js.map +1 -1
- package/dist/src/platforms/teams/cli.d.ts.map +1 -0
- package/dist/{cli.js → src/platforms/teams/cli.js} +11 -10
- package/dist/src/platforms/teams/cli.js.map +1 -0
- package/dist/src/platforms/teams/client.d.ts +32 -0
- package/dist/src/platforms/teams/client.d.ts.map +1 -0
- package/dist/src/platforms/teams/client.js +202 -0
- package/dist/src/platforms/teams/client.js.map +1 -0
- package/dist/src/platforms/teams/commands/auth.d.ts +14 -0
- package/dist/src/platforms/teams/commands/auth.d.ts.map +1 -0
- package/dist/src/platforms/teams/commands/auth.js +176 -0
- package/dist/src/platforms/teams/commands/auth.js.map +1 -0
- package/dist/src/platforms/teams/commands/channel.d.ts +13 -0
- package/dist/src/platforms/teams/commands/channel.d.ts.map +1 -0
- package/dist/src/platforms/teams/commands/channel.js +97 -0
- package/dist/src/platforms/teams/commands/channel.js.map +1 -0
- package/dist/src/platforms/teams/commands/file.d.ts +12 -0
- package/dist/src/platforms/teams/commands/file.d.ts.map +1 -0
- package/dist/src/platforms/teams/commands/file.js +104 -0
- package/dist/src/platforms/teams/commands/file.js.map +1 -0
- package/dist/{commands → src/platforms/teams/commands}/index.d.ts +5 -2
- package/dist/src/platforms/teams/commands/index.d.ts.map +1 -0
- package/dist/{commands → src/platforms/teams/commands}/index.js +5 -2
- package/dist/src/platforms/teams/commands/index.js.map +1 -0
- package/dist/src/platforms/teams/commands/message.d.ts +17 -0
- package/dist/src/platforms/teams/commands/message.d.ts.map +1 -0
- package/dist/src/platforms/teams/commands/message.js +133 -0
- package/dist/src/platforms/teams/commands/message.js.map +1 -0
- package/dist/src/platforms/teams/commands/reaction.d.ts +9 -0
- package/dist/src/platforms/teams/commands/reaction.d.ts.map +1 -0
- package/dist/src/platforms/teams/commands/reaction.js +68 -0
- package/dist/src/platforms/teams/commands/reaction.js.map +1 -0
- package/dist/src/platforms/teams/commands/snapshot.d.ts +10 -0
- package/dist/src/platforms/teams/commands/snapshot.d.ts.map +1 -0
- package/dist/src/platforms/teams/commands/snapshot.js +85 -0
- package/dist/src/platforms/teams/commands/snapshot.js.map +1 -0
- package/dist/src/platforms/teams/commands/team.d.ts +18 -0
- package/dist/src/platforms/teams/commands/team.d.ts.map +1 -0
- package/dist/src/platforms/teams/commands/team.js +130 -0
- package/dist/src/platforms/teams/commands/team.js.map +1 -0
- package/dist/src/platforms/teams/commands/user.d.ts.map +1 -0
- package/dist/src/platforms/teams/commands/user.js +88 -0
- package/dist/src/platforms/teams/commands/user.js.map +1 -0
- package/dist/src/platforms/teams/credential-manager.d.ts +18 -0
- package/dist/src/platforms/teams/credential-manager.d.ts.map +1 -0
- package/dist/src/platforms/teams/credential-manager.js +81 -0
- package/dist/src/platforms/teams/credential-manager.js.map +1 -0
- package/dist/src/platforms/teams/index.d.ts +4 -0
- package/dist/src/platforms/teams/index.d.ts.map +1 -0
- package/dist/src/platforms/teams/index.js +6 -0
- package/dist/src/platforms/teams/index.js.map +1 -0
- package/dist/src/platforms/teams/token-extractor.d.ts +36 -0
- package/dist/src/platforms/teams/token-extractor.d.ts.map +1 -0
- package/dist/src/platforms/teams/token-extractor.js +335 -0
- package/dist/src/platforms/teams/token-extractor.js.map +1 -0
- package/dist/src/platforms/teams/types.d.ts +209 -0
- package/dist/src/platforms/teams/types.d.ts.map +1 -0
- package/dist/src/platforms/teams/types.js +65 -0
- package/dist/src/platforms/teams/types.js.map +1 -0
- package/docs/teams.md +321 -0
- package/e2e/README.md +256 -0
- package/e2e/config.ts +45 -0
- package/e2e/discord.e2e.test.ts +252 -0
- package/e2e/helpers.ts +107 -0
- package/e2e/slack.e2e.test.ts +309 -0
- package/package.json +8 -4
- package/scripts/postbuild.ts +15 -0
- package/skills/agent-teams/SKILL.md +292 -0
- package/skills/agent-teams/references/authentication.md +375 -0
- package/skills/agent-teams/references/common-patterns.md +596 -0
- package/skills/agent-teams/templates/monitor-channel.sh +239 -0
- package/skills/agent-teams/templates/post-message.sh +224 -0
- package/skills/agent-teams/templates/team-summary.sh +210 -0
- package/src/cli.ts +4 -0
- package/src/platforms/discord/client.ts +3 -3
- package/src/platforms/discord/commands/auth.test.ts +48 -32
- package/src/platforms/discord/commands/channel.test.ts +54 -42
- package/src/platforms/discord/commands/file.test.ts +40 -53
- package/src/platforms/discord/commands/guild.test.ts +47 -27
- package/src/platforms/discord/commands/message.test.ts +54 -51
- package/src/platforms/discord/commands/reaction.test.ts +54 -42
- package/src/platforms/discord/commands/user.ts +12 -1
- package/src/platforms/discord/credential-manager.test.ts +137 -136
- package/src/platforms/discord/credential-manager.ts +20 -13
- package/src/platforms/discord/token-extractor.test.ts +133 -383
- package/{tests → src/platforms/slack}/cli.test.ts +3 -3
- package/{tests/slack-client.test.ts → src/platforms/slack/client.test.ts} +1 -1
- package/{tests → src/platforms/slack}/commands/auth.test.ts +25 -13
- package/{tests → src/platforms/slack}/commands/channel.test.ts +2 -2
- package/{tests → src/platforms/slack}/commands/file.test.ts +2 -2
- package/{tests → src/platforms/slack}/commands/message.test.ts +2 -2
- package/{tests → src/platforms/slack}/commands/reaction.test.ts +1 -1
- package/{tests → src/platforms/slack}/commands/snapshot.test.ts +117 -105
- package/{tests → src/platforms/slack}/commands/user.test.ts +3 -3
- package/{tests → src/platforms/slack}/commands/workspace.test.ts +44 -95
- package/{tests → src/platforms/slack}/credential-manager.test.ts +2 -2
- package/src/platforms/slack/credential-manager.ts +22 -7
- package/src/platforms/slack/token-extractor-node-test.ts +40 -0
- package/src/platforms/slack/token-extractor-node.test.ts +10 -0
- package/src/platforms/slack/token-extractor.ts +36 -10
- package/{tests → src/platforms/slack}/types.test.ts +1 -1
- package/src/platforms/teams/cli.ts +36 -0
- package/src/platforms/teams/client.test.ts +500 -0
- package/src/platforms/teams/client.ts +365 -0
- package/src/platforms/teams/commands/auth.test.ts +99 -0
- package/src/platforms/teams/commands/auth.ts +232 -0
- package/src/platforms/teams/commands/channel.test.ts +147 -0
- package/src/platforms/teams/commands/channel.ts +129 -0
- package/src/platforms/teams/commands/file.test.ts +88 -0
- package/src/platforms/teams/commands/file.ts +144 -0
- package/src/platforms/teams/commands/index.ts +12 -0
- package/src/platforms/teams/commands/message.test.ts +110 -0
- package/src/platforms/teams/commands/message.ts +188 -0
- package/src/platforms/teams/commands/reaction.test.ts +87 -0
- package/src/platforms/teams/commands/reaction.ts +104 -0
- package/src/platforms/teams/commands/snapshot.test.ts +35 -0
- package/src/platforms/teams/commands/snapshot.ts +115 -0
- package/src/platforms/teams/commands/team.test.ts +157 -0
- package/src/platforms/teams/commands/team.ts +164 -0
- package/src/platforms/teams/commands/user.test.ts +83 -0
- package/src/platforms/teams/commands/user.ts +112 -0
- package/src/platforms/teams/credential-manager.test.ts +178 -0
- package/src/platforms/teams/credential-manager.ts +92 -0
- package/src/platforms/teams/index.ts +5 -0
- package/src/platforms/teams/token-extractor.test.ts +429 -0
- package/src/platforms/teams/token-extractor.ts +462 -0
- package/src/platforms/teams/types.test.ts +226 -0
- package/src/platforms/teams/types.ts +140 -0
- package/tsconfig.json +1 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/commands/auth.d.ts +0 -3
- package/dist/commands/auth.d.ts.map +0 -1
- package/dist/commands/auth.js +0 -140
- package/dist/commands/auth.js.map +0 -1
- package/dist/commands/channel.d.ts +0 -3
- package/dist/commands/channel.d.ts.map +0 -1
- package/dist/commands/channel.js +0 -118
- package/dist/commands/channel.js.map +0 -1
- package/dist/commands/file.d.ts +0 -3
- package/dist/commands/file.d.ts.map +0 -1
- package/dist/commands/file.js +0 -113
- package/dist/commands/file.js.map +0 -1
- package/dist/commands/index.d.ts.map +0 -1
- package/dist/commands/index.js.map +0 -1
- package/dist/commands/message.d.ts +0 -3
- package/dist/commands/message.d.ts.map +0 -1
- package/dist/commands/message.js +0 -214
- package/dist/commands/message.js.map +0 -1
- package/dist/commands/reaction.d.ts +0 -3
- package/dist/commands/reaction.d.ts.map +0 -1
- package/dist/commands/reaction.js +0 -100
- package/dist/commands/reaction.js.map +0 -1
- package/dist/commands/snapshot.d.ts +0 -3
- package/dist/commands/snapshot.d.ts.map +0 -1
- package/dist/commands/snapshot.js +0 -88
- package/dist/commands/snapshot.js.map +0 -1
- package/dist/commands/user.d.ts.map +0 -1
- package/dist/commands/user.js +0 -96
- package/dist/commands/user.js.map +0 -1
- package/dist/commands/workspace.d.ts +0 -3
- package/dist/commands/workspace.d.ts.map +0 -1
- package/dist/commands/workspace.js +0 -89
- package/dist/commands/workspace.js.map +0 -1
- package/dist/lib/credential-manager.d.ts +0 -13
- package/dist/lib/credential-manager.d.ts.map +0 -1
- package/dist/lib/credential-manager.js +0 -58
- package/dist/lib/credential-manager.js.map +0 -1
- package/dist/lib/index.d.ts +0 -3
- package/dist/lib/index.d.ts.map +0 -1
- package/dist/lib/index.js +0 -3
- package/dist/lib/index.js.map +0 -1
- package/dist/lib/ref-manager.d.ts +0 -26
- package/dist/lib/ref-manager.d.ts.map +0 -1
- package/dist/lib/ref-manager.js +0 -92
- package/dist/lib/ref-manager.js.map +0 -1
- package/dist/lib/slack-client.d.ts +0 -37
- package/dist/lib/slack-client.d.ts.map +0 -1
- package/dist/lib/slack-client.js +0 -379
- package/dist/lib/slack-client.js.map +0 -1
- package/dist/lib/token-extractor.d.ts +0 -28
- package/dist/lib/token-extractor.d.ts.map +0 -1
- package/dist/lib/token-extractor.js +0 -401
- package/dist/lib/token-extractor.js.map +0 -1
- package/dist/src/platforms/discord/client.test.d.ts +0 -2
- package/dist/src/platforms/discord/client.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/client.test.js +0 -367
- package/dist/src/platforms/discord/client.test.js.map +0 -1
- package/dist/src/platforms/discord/commands/auth.test.d.ts +0 -2
- package/dist/src/platforms/discord/commands/auth.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/commands/auth.test.js +0 -65
- package/dist/src/platforms/discord/commands/auth.test.js.map +0 -1
- package/dist/src/platforms/discord/commands/channel.test.d.ts +0 -2
- package/dist/src/platforms/discord/commands/channel.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/commands/channel.test.js +0 -136
- package/dist/src/platforms/discord/commands/channel.test.js.map +0 -1
- package/dist/src/platforms/discord/commands/file.test.d.ts +0 -2
- package/dist/src/platforms/discord/commands/file.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/commands/file.test.js +0 -83
- package/dist/src/platforms/discord/commands/file.test.js.map +0 -1
- package/dist/src/platforms/discord/commands/guild.test.d.ts +0 -2
- package/dist/src/platforms/discord/commands/guild.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/commands/guild.test.js +0 -100
- package/dist/src/platforms/discord/commands/guild.test.js.map +0 -1
- package/dist/src/platforms/discord/commands/message.test.d.ts +0 -2
- package/dist/src/platforms/discord/commands/message.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/commands/message.test.js +0 -91
- package/dist/src/platforms/discord/commands/message.test.js.map +0 -1
- package/dist/src/platforms/discord/commands/reaction.test.d.ts +0 -2
- package/dist/src/platforms/discord/commands/reaction.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/commands/reaction.test.js +0 -115
- package/dist/src/platforms/discord/commands/reaction.test.js.map +0 -1
- package/dist/src/platforms/discord/commands/snapshot.test.d.ts +0 -2
- package/dist/src/platforms/discord/commands/snapshot.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/commands/snapshot.test.js +0 -25
- package/dist/src/platforms/discord/commands/snapshot.test.js.map +0 -1
- package/dist/src/platforms/discord/commands/user.test.d.ts +0 -2
- package/dist/src/platforms/discord/commands/user.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/commands/user.test.js +0 -103
- package/dist/src/platforms/discord/commands/user.test.js.map +0 -1
- package/dist/src/platforms/discord/credential-manager.test.d.ts +0 -2
- package/dist/src/platforms/discord/credential-manager.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/credential-manager.test.js +0 -136
- package/dist/src/platforms/discord/credential-manager.test.js.map +0 -1
- package/dist/src/platforms/discord/token-extractor.test.d.ts +0 -2
- package/dist/src/platforms/discord/token-extractor.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/token-extractor.test.js +0 -789
- package/dist/src/platforms/discord/token-extractor.test.js.map +0 -1
- package/dist/src/platforms/discord/types.test.d.ts +0 -2
- package/dist/src/platforms/discord/types.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/types.test.js +0 -211
- package/dist/src/platforms/discord/types.test.js.map +0 -1
- package/dist/src/shared/utils/concurrency.test.d.ts +0 -2
- package/dist/src/shared/utils/concurrency.test.d.ts.map +0 -1
- package/dist/src/shared/utils/concurrency.test.js +0 -39
- package/dist/src/shared/utils/concurrency.test.js.map +0 -1
- package/dist/tests/cli.test.d.ts +0 -2
- package/dist/tests/cli.test.d.ts.map +0 -1
- package/dist/tests/cli.test.js +0 -83
- package/dist/tests/cli.test.js.map +0 -1
- package/dist/tests/commands/.test-slack-data/Local Storage/leveldb/CURRENT +0 -1
- package/dist/tests/commands/.test-slack-data/Local Storage/leveldb/LOCK +0 -0
- package/dist/tests/commands/.test-slack-data/Local Storage/leveldb/LOG +0 -3
- package/dist/tests/commands/.test-slack-data/Local Storage/leveldb/LOG.old +0 -1
- package/dist/tests/commands/.test-slack-data/Local Storage/leveldb/MANIFEST-000004 +0 -0
- package/dist/tests/commands/auth.test.d.ts +0 -2
- package/dist/tests/commands/auth.test.d.ts.map +0 -1
- package/dist/tests/commands/auth.test.js +0 -304
- package/dist/tests/commands/auth.test.js.map +0 -1
- package/dist/tests/commands/channel.test.d.ts +0 -2
- package/dist/tests/commands/channel.test.d.ts.map +0 -1
- package/dist/tests/commands/channel.test.js +0 -166
- package/dist/tests/commands/channel.test.js.map +0 -1
- package/dist/tests/commands/file.test.d.ts +0 -2
- package/dist/tests/commands/file.test.d.ts.map +0 -1
- package/dist/tests/commands/file.test.js +0 -175
- package/dist/tests/commands/file.test.js.map +0 -1
- package/dist/tests/commands/message.test.d.ts +0 -2
- package/dist/tests/commands/message.test.d.ts.map +0 -1
- package/dist/tests/commands/message.test.js +0 -293
- package/dist/tests/commands/message.test.js.map +0 -1
- package/dist/tests/commands/reaction.test.d.ts +0 -2
- package/dist/tests/commands/reaction.test.d.ts.map +0 -1
- package/dist/tests/commands/reaction.test.js +0 -84
- package/dist/tests/commands/reaction.test.js.map +0 -1
- package/dist/tests/commands/snapshot.test.d.ts +0 -2
- package/dist/tests/commands/snapshot.test.d.ts.map +0 -1
- package/dist/tests/commands/snapshot.test.js +0 -280
- package/dist/tests/commands/snapshot.test.js.map +0 -1
- package/dist/tests/commands/user.test.d.ts +0 -2
- package/dist/tests/commands/user.test.d.ts.map +0 -1
- package/dist/tests/commands/user.test.js +0 -117
- package/dist/tests/commands/user.test.js.map +0 -1
- package/dist/tests/commands/workspace.test.d.ts +0 -2
- package/dist/tests/commands/workspace.test.d.ts.map +0 -1
- package/dist/tests/commands/workspace.test.js +0 -453
- package/dist/tests/commands/workspace.test.js.map +0 -1
- package/dist/tests/credential-manager.test.d.ts +0 -2
- package/dist/tests/credential-manager.test.d.ts.map +0 -1
- package/dist/tests/credential-manager.test.js +0 -199
- package/dist/tests/credential-manager.test.js.map +0 -1
- package/dist/tests/slack-client.test.d.ts +0 -2
- package/dist/tests/slack-client.test.d.ts.map +0 -1
- package/dist/tests/slack-client.test.js +0 -741
- package/dist/tests/slack-client.test.js.map +0 -1
- package/dist/tests/types.test.d.ts +0 -2
- package/dist/tests/types.test.d.ts.map +0 -1
- package/dist/tests/types.test.js +0 -215
- package/dist/tests/types.test.js.map +0 -1
- package/dist/types/index.d.ts +0 -369
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -92
- package/dist/types/index.js.map +0 -1
- package/dist/utils/error-handler.d.ts +0 -2
- package/dist/utils/error-handler.d.ts.map +0 -1
- package/dist/utils/error-handler.js +0 -5
- package/dist/utils/error-handler.js.map +0 -1
- package/dist/utils/output.d.ts +0 -2
- package/dist/utils/output.d.ts.map +0 -1
- package/dist/utils/output.js +0 -4
- package/dist/utils/output.js.map +0 -1
- /package/dist/{cli.d.ts → src/platforms/teams/cli.d.ts} +0 -0
- /package/dist/{commands → src/platforms/teams/commands}/user.d.ts +0 -0
|
@@ -1,173 +1,174 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { existsSync } from 'node:fs'
|
|
3
|
-
import { rm } from 'node:fs/promises'
|
|
1
|
+
import { afterAll, describe, expect, test } from 'bun:test'
|
|
2
|
+
import { existsSync, rmSync } from 'node:fs'
|
|
4
3
|
import { join } from 'node:path'
|
|
5
4
|
import { DiscordCredentialManager } from './credential-manager'
|
|
6
5
|
|
|
7
|
-
const
|
|
6
|
+
const testDirs: string[] = []
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
function setup(): DiscordCredentialManager {
|
|
9
|
+
const testConfigDir = join(
|
|
10
|
+
import.meta.dir,
|
|
11
|
+
`.test-discord-config-${Date.now()}-${Math.random().toString(36).slice(2)}`
|
|
12
|
+
)
|
|
13
|
+
testDirs.push(testConfigDir)
|
|
14
|
+
return new DiscordCredentialManager(testConfigDir)
|
|
15
|
+
}
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
afterAll(() => {
|
|
18
|
+
for (const dir of testDirs) {
|
|
19
|
+
rmSync(dir, { recursive: true, force: true })
|
|
18
20
|
}
|
|
19
21
|
})
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
describe('DiscordCredentialManager', () => {
|
|
24
|
+
test('load returns default config when file does not exist', async () => {
|
|
25
|
+
const manager = setup()
|
|
26
|
+
const config = await manager.load()
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
expect(config).toEqual({
|
|
29
|
+
token: null,
|
|
30
|
+
current_guild: null,
|
|
31
|
+
guilds: {},
|
|
32
|
+
})
|
|
29
33
|
})
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
test('save creates config file with correct permissions', async () => {
|
|
33
|
-
const manager = new DiscordCredentialManager(TEST_CONFIG_DIR)
|
|
34
|
-
const config = {
|
|
35
|
-
token: 'test-token',
|
|
36
|
-
current_guild: 'guild-123',
|
|
37
|
-
guilds: {
|
|
38
|
-
'guild-123': { guild_id: 'guild-123', guild_name: 'Test Guild' },
|
|
39
|
-
},
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
await manager.save(config)
|
|
43
|
-
|
|
44
|
-
const credentialsPath = join(TEST_CONFIG_DIR, 'discord-credentials.json')
|
|
45
|
-
expect(existsSync(credentialsPath)).toBe(true)
|
|
46
|
-
|
|
47
|
-
const file = Bun.file(credentialsPath)
|
|
48
|
-
const content = await file.text()
|
|
49
|
-
const loaded = JSON.parse(content)
|
|
50
|
-
expect(loaded).toEqual(config)
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
test('getToken returns null when not authenticated', async () => {
|
|
54
|
-
const manager = new DiscordCredentialManager(TEST_CONFIG_DIR)
|
|
55
|
-
const token = await manager.getToken()
|
|
56
34
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
test
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
35
|
+
test('save creates config file with correct permissions', async () => {
|
|
36
|
+
const testConfigDir = join(
|
|
37
|
+
import.meta.dir,
|
|
38
|
+
`.test-discord-config-${Date.now()}-${Math.random().toString(36).slice(2)}`
|
|
39
|
+
)
|
|
40
|
+
testDirs.push(testConfigDir)
|
|
41
|
+
const manager = new DiscordCredentialManager(testConfigDir)
|
|
42
|
+
const config = {
|
|
43
|
+
token: 'test-token',
|
|
44
|
+
current_guild: 'guild-123',
|
|
45
|
+
guilds: {
|
|
46
|
+
'guild-123': { guild_id: 'guild-123', guild_name: 'Test Guild' },
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
await manager.save(config)
|
|
51
|
+
|
|
52
|
+
const credentialsPath = join(testConfigDir, 'discord-credentials.json')
|
|
53
|
+
expect(existsSync(credentialsPath)).toBe(true)
|
|
54
|
+
|
|
55
|
+
const file = Bun.file(credentialsPath)
|
|
56
|
+
const content = await file.text()
|
|
57
|
+
const loaded = JSON.parse(content)
|
|
58
|
+
expect(loaded).toEqual(config)
|
|
59
|
+
})
|
|
67
60
|
|
|
68
|
-
test('getToken returns
|
|
69
|
-
|
|
70
|
-
|
|
61
|
+
test('getToken returns null when not authenticated', async () => {
|
|
62
|
+
const manager = setup()
|
|
63
|
+
const token = await manager.getToken()
|
|
64
|
+
expect(token).toBeNull()
|
|
65
|
+
})
|
|
71
66
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
test('setToken saves token to config', async () => {
|
|
68
|
+
const manager = setup()
|
|
69
|
+
await manager.setToken('test-token-123')
|
|
75
70
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
await manager.clearToken()
|
|
71
|
+
const token = await manager.getToken()
|
|
72
|
+
expect(token).toBe('test-token-123')
|
|
73
|
+
})
|
|
80
74
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
75
|
+
test('getToken returns previously set token', async () => {
|
|
76
|
+
const manager = setup()
|
|
77
|
+
await manager.setToken('my-token')
|
|
84
78
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
79
|
+
const token = await manager.getToken()
|
|
80
|
+
expect(token).toBe('my-token')
|
|
81
|
+
})
|
|
88
82
|
|
|
89
|
-
|
|
90
|
-
|
|
83
|
+
test('clearToken removes token from config', async () => {
|
|
84
|
+
const manager = setup()
|
|
85
|
+
await manager.setToken('test-token')
|
|
86
|
+
await manager.clearToken()
|
|
91
87
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
const token = await manager.getToken()
|
|
89
|
+
expect(token).toBeNull()
|
|
90
|
+
})
|
|
95
91
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
test('getCurrentGuild returns null when not set', async () => {
|
|
93
|
+
const manager = setup()
|
|
94
|
+
const guild = await manager.getCurrentGuild()
|
|
95
|
+
expect(guild).toBeNull()
|
|
96
|
+
})
|
|
99
97
|
|
|
100
|
-
test('
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
test('setCurrentGuild saves guild id', async () => {
|
|
99
|
+
const manager = setup()
|
|
100
|
+
await manager.setCurrentGuild('guild-456')
|
|
103
101
|
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
const guild = await manager.getCurrentGuild()
|
|
103
|
+
expect(guild).toBe('guild-456')
|
|
104
|
+
})
|
|
106
105
|
|
|
107
|
-
test('
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
106
|
+
test('getGuilds returns empty object when no guilds set', async () => {
|
|
107
|
+
const manager = setup()
|
|
108
|
+
const guilds = await manager.getGuilds()
|
|
109
|
+
expect(guilds).toEqual({})
|
|
110
|
+
})
|
|
113
111
|
|
|
114
|
-
|
|
112
|
+
test('setGuilds saves guilds to config', async () => {
|
|
113
|
+
const manager = setup()
|
|
114
|
+
const guilds = {
|
|
115
|
+
'guild-1': { guild_id: 'guild-1', guild_name: 'Guild One' },
|
|
116
|
+
'guild-2': { guild_id: 'guild-2', guild_name: 'Guild Two' },
|
|
117
|
+
}
|
|
115
118
|
|
|
116
|
-
|
|
117
|
-
expect(loaded).toEqual(guilds)
|
|
118
|
-
})
|
|
119
|
+
await manager.setGuilds(guilds)
|
|
119
120
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
const loaded = await manager.getGuilds()
|
|
122
|
+
expect(loaded).toEqual(guilds)
|
|
123
|
+
})
|
|
123
124
|
|
|
124
|
-
|
|
125
|
-
|
|
125
|
+
test('getCredentials returns null when not authenticated', async () => {
|
|
126
|
+
const manager = setup()
|
|
127
|
+
const creds = await manager.getCredentials()
|
|
128
|
+
expect(creds).toBeNull()
|
|
129
|
+
})
|
|
126
130
|
|
|
127
|
-
test('getCredentials returns null when token exists but no guild selected', async () => {
|
|
128
|
-
|
|
129
|
-
|
|
131
|
+
test('getCredentials returns null when token exists but no guild selected', async () => {
|
|
132
|
+
const manager = setup()
|
|
133
|
+
await manager.setToken('test-token')
|
|
130
134
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
})
|
|
135
|
+
const creds = await manager.getCredentials()
|
|
136
|
+
expect(creds).toBeNull()
|
|
137
|
+
})
|
|
134
138
|
|
|
135
|
-
test('getCredentials returns null when guild selected but no token', async () => {
|
|
136
|
-
|
|
137
|
-
|
|
139
|
+
test('getCredentials returns null when guild selected but no token', async () => {
|
|
140
|
+
const manager = setup()
|
|
141
|
+
await manager.setCurrentGuild('guild-123')
|
|
138
142
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
})
|
|
143
|
+
const creds = await manager.getCredentials()
|
|
144
|
+
expect(creds).toBeNull()
|
|
145
|
+
})
|
|
142
146
|
|
|
143
|
-
test('getCredentials returns token and guildId when both are set', async () => {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
+
test('getCredentials returns token and guildId when both are set', async () => {
|
|
148
|
+
const manager = setup()
|
|
149
|
+
await manager.setToken('test-token-xyz')
|
|
150
|
+
await manager.setCurrentGuild('guild-789')
|
|
147
151
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
+
const creds = await manager.getCredentials()
|
|
153
|
+
expect(creds).toEqual({
|
|
154
|
+
token: 'test-token-xyz',
|
|
155
|
+
guildId: 'guild-789',
|
|
156
|
+
})
|
|
152
157
|
})
|
|
153
|
-
})
|
|
154
158
|
|
|
155
|
-
test('multiple operations preserve existing data', async () => {
|
|
156
|
-
|
|
159
|
+
test('multiple operations preserve existing data', async () => {
|
|
160
|
+
const manager = setup()
|
|
161
|
+
await manager.setToken('token-1')
|
|
162
|
+
await manager.setCurrentGuild('guild-1')
|
|
163
|
+
const guilds = {
|
|
164
|
+
'guild-1': { guild_id: 'guild-1', guild_name: 'Guild One' },
|
|
165
|
+
}
|
|
166
|
+
await manager.setGuilds(guilds)
|
|
157
167
|
|
|
158
|
-
|
|
159
|
-
await manager.setToken('token-1')
|
|
160
|
-
await manager.setCurrentGuild('guild-1')
|
|
161
|
-
const guilds = {
|
|
162
|
-
'guild-1': { guild_id: 'guild-1', guild_name: 'Guild One' },
|
|
163
|
-
}
|
|
164
|
-
await manager.setGuilds(guilds)
|
|
168
|
+
await manager.setToken('token-2')
|
|
165
169
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
expect(await manager.getToken()).toBe('token-2')
|
|
171
|
-
expect(await manager.getCurrentGuild()).toBe('guild-1')
|
|
172
|
-
expect(await manager.getGuilds()).toEqual(guilds)
|
|
170
|
+
expect(await manager.getToken()).toBe('token-2')
|
|
171
|
+
expect(await manager.getCurrentGuild()).toBe('guild-1')
|
|
172
|
+
expect(await manager.getGuilds()).toEqual(guilds)
|
|
173
|
+
})
|
|
173
174
|
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs'
|
|
2
|
-
import { mkdir } from 'node:fs/promises'
|
|
2
|
+
import { chmod, mkdir, readFile, writeFile } from 'node:fs/promises'
|
|
3
3
|
import { homedir } from 'node:os'
|
|
4
4
|
import { join } from 'node:path'
|
|
5
5
|
|
|
@@ -27,21 +27,24 @@ export class DiscordCredentialManager {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
const
|
|
31
|
-
const content = await file.text()
|
|
30
|
+
const content = await readFile(this.credentialsPath, 'utf-8')
|
|
32
31
|
return JSON.parse(content) as DiscordConfig
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
async save(config: DiscordConfig): Promise<void> {
|
|
36
35
|
await mkdir(this.configDir, { recursive: true })
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
await
|
|
40
|
-
|
|
41
|
-
await Bun.spawn(['chmod', '0600', this.credentialsPath]).exited
|
|
37
|
+
await writeFile(this.credentialsPath, JSON.stringify(config, null, 2))
|
|
38
|
+
await chmod(this.credentialsPath, 0o600)
|
|
42
39
|
}
|
|
43
40
|
|
|
44
41
|
async getToken(): Promise<string | null> {
|
|
42
|
+
// Check env var first (takes precedence over file-based credentials)
|
|
43
|
+
const envToken = process.env.E2E_DISCORD_TOKEN
|
|
44
|
+
if (envToken) {
|
|
45
|
+
return envToken
|
|
46
|
+
}
|
|
47
|
+
|
|
45
48
|
const config = await this.load()
|
|
46
49
|
return config.token
|
|
47
50
|
}
|
|
@@ -59,6 +62,12 @@ export class DiscordCredentialManager {
|
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
async getCurrentGuild(): Promise<string | null> {
|
|
65
|
+
// Check env var first (takes precedence over file-based credentials)
|
|
66
|
+
const envGuildId = process.env.E2E_DISCORD_GUILD_ID
|
|
67
|
+
if (envGuildId) {
|
|
68
|
+
return envGuildId
|
|
69
|
+
}
|
|
70
|
+
|
|
62
71
|
const config = await this.load()
|
|
63
72
|
return config.current_guild
|
|
64
73
|
}
|
|
@@ -81,15 +90,13 @@ export class DiscordCredentialManager {
|
|
|
81
90
|
}
|
|
82
91
|
|
|
83
92
|
async getCredentials(): Promise<{ token: string; guildId: string } | null> {
|
|
84
|
-
const
|
|
93
|
+
const token = await this.getToken()
|
|
94
|
+
const guildId = await this.getCurrentGuild()
|
|
85
95
|
|
|
86
|
-
if (!
|
|
96
|
+
if (!token || !guildId) {
|
|
87
97
|
return null
|
|
88
98
|
}
|
|
89
99
|
|
|
90
|
-
return {
|
|
91
|
-
token: config.token,
|
|
92
|
-
guildId: config.current_guild,
|
|
93
|
-
}
|
|
100
|
+
return { token, guildId }
|
|
94
101
|
}
|
|
95
102
|
}
|