-
Notifications
You must be signed in to change notification settings - Fork 137
feat: add SUNSET_MODE to wind down the bot #911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,9 +32,14 @@ if ( | |
| macaroon = fs.readFileSync(macaroonPath).toString('base64'); | ||
| } | ||
|
|
||
| // Enforcing presence of LND_GRPC_HOST environment variable | ||
| // Enforcing presence of LND_GRPC_HOST environment variable, | ||
| // not needed in sunset mode because the node is never called | ||
| const socket = process.env.LND_GRPC_HOST; | ||
| if (!socket && process.env.NODE_ENV !== 'test') { | ||
| if ( | ||
| !socket && | ||
| process.env.NODE_ENV !== 'test' && | ||
| process.env.SUNSET_MODE !== 'true' | ||
|
Comment on lines
+38
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When AGENTS.md reference: AGENTS.md:L9-L10 Useful? React with 👍 / 👎.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verified empirically against the pinned Reproduction: The existing test suite already relies on this same behavior: tests import |
||
| ) { | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| throw new Error('You must provide a LND_GRPC_HOST environment variable'); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import path from 'path'; | ||
| import fs from 'fs'; | ||
|
|
||
| import { sunsetMiddleware } from '../../bot/start'; | ||
| import { User } from '../../models'; | ||
|
|
||
| const sinon = require('sinon'); | ||
| const { expect } = require('chai'); | ||
|
|
||
| const SPANISH_ANNOUNCEMENT = | ||
| 'https://x.com/negrunch/status/2086896990256799795'; | ||
| const ENGLISH_ANNOUNCEMENT = | ||
| 'https://x.com/negrunch/status/2086899005355704703'; | ||
|
|
||
| const makeCtx = (from: any) => { | ||
| const locales: string[] = []; | ||
| return { | ||
| from, | ||
| i18n: { | ||
| locale: (lang: string) => locales.push(lang), | ||
| t: (key: string) => `translated:${key}`, | ||
| }, | ||
| reply: sinon.stub().resolves(), | ||
| locales, | ||
| }; | ||
| }; | ||
|
|
||
| describe('sunset mode', () => { | ||
| let sandbox: any; | ||
|
|
||
| beforeEach(() => { | ||
| sandbox = sinon.createSandbox(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| sandbox.restore(); | ||
| }); | ||
|
|
||
| describe('sunsetMiddleware', () => { | ||
| it('replies with the sunset notice in the language stored for the user', async () => { | ||
| sandbox.stub(User, 'findOne').resolves({ lang: 'es' }); | ||
| const ctx = makeCtx({ id: 1, language_code: 'de' }); | ||
|
|
||
| await sunsetMiddleware(ctx as any); | ||
|
|
||
| expect(ctx.locales).to.deep.equal(['es']); | ||
| expect(ctx.reply.calledOnce).to.equal(true); | ||
| expect(ctx.reply.firstCall.args[0]).to.equal('translated:sunset'); | ||
| }); | ||
|
|
||
| it('falls back to the Telegram client language when the user is unknown', async () => { | ||
| sandbox.stub(User, 'findOne').resolves(null); | ||
| const ctx = makeCtx({ id: 1, language_code: 'fr' }); | ||
|
|
||
| await sunsetMiddleware(ctx as any); | ||
|
|
||
| expect(ctx.locales).to.deep.equal(['fr']); | ||
| expect(ctx.reply.calledOnce).to.equal(true); | ||
| }); | ||
|
|
||
| it('falls back to English when no language can be determined', async () => { | ||
| sandbox.stub(User, 'findOne').resolves(null); | ||
| const ctx = makeCtx({ id: 1 }); | ||
|
|
||
| await sunsetMiddleware(ctx as any); | ||
|
|
||
| expect(ctx.locales).to.deep.equal(['en']); | ||
| expect(ctx.reply.calledOnce).to.equal(true); | ||
| }); | ||
|
|
||
| it('does not reply when the update has no sender', async () => { | ||
| const findOne = sandbox.stub(User, 'findOne'); | ||
| const ctx = makeCtx(undefined); | ||
|
|
||
| await sunsetMiddleware(ctx as any); | ||
|
|
||
| expect(findOne.called).to.equal(false); | ||
| expect(ctx.reply.called).to.equal(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('sunset locale messages', () => { | ||
| const readLocale = (lang: string) => | ||
| fs.readFileSync( | ||
| path.join(__dirname, '../../../locales', `${lang}.yaml`), | ||
| 'utf8', | ||
| ); | ||
|
|
||
| it('spanish message links to the spanish announcement and Mostro', () => { | ||
| const es = readLocale('es'); | ||
| expect(es).to.include('sunset:'); | ||
| expect(es).to.include(SPANISH_ANNOUNCEMENT); | ||
| expect(es).to.include('https://mostro.network'); | ||
| expect(es).to.include('https://mostro.community'); | ||
| }); | ||
|
|
||
| it('english message links to the english announcement and Mostro', () => { | ||
| const en = readLocale('en'); | ||
| expect(en).to.include('sunset:'); | ||
| expect(en).to.include(ENGLISH_ANNOUNCEMENT); | ||
| expect(en).to.include('https://mostro.network'); | ||
| expect(en).to.include('https://mostro.community'); | ||
| }); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.