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
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

10 changes: 7 additions & 3 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,19 @@ jobs:
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: npm

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: latest

- name: Install Dependencies
id: install
run: npm ci
run: pnpm install

- name: Build dist/ Directory
id: build
run: npm run bundle
run: pnpm run bundle

# This will fail the workflow if the `dist/` directory is different than
# expected.
Expand Down
21 changes: 13 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ on:
pull_request:
branches:
- main
- develop
push:
branches:
- main
- '**'

permissions:
contents: read
Expand All @@ -26,19 +27,23 @@ jobs:
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: npm

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: latest

- name: Install Dependencies
id: npm-ci
run: npm ci
id: pnpm-install
run: pnpm install

- name: Check Format
id: npm-format-check
run: npm run format:check
id: pnpm-format-check
run: pnpm run format:check

- name: Test
id: npm-ci-test
run: npm run ci-test
id: pnpm-ci-test
run: pnpm run ci-test

test-action:
name: GitHub Actions Test
Expand Down
29 changes: 14 additions & 15 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ on:
pull_request:
branches:
- main
- develop
push:
branches:
- main
- '**'

permissions:
contents: read
Expand All @@ -30,20 +31,18 @@ jobs:
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: npm

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: latest

- name: Install Dependencies
id: install
run: npm ci

- name: Lint Codebase
id: super-linter
uses: super-linter/super-linter/slim@v7
env:
DEFAULT_BRANCH: main
FILTER_REGEX_EXCLUDE: dist/**/*
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_ALL_CODEBASE: true
VALIDATE_JAVASCRIPT_STANDARD: false
VALIDATE_JSCPD: false
VALIDATE_TYPESCRIPT_STANDARD: false
run: pnpm install

- name: Lint TypeScript
run: pnpm run lint

- name: Check Format
run: pnpm run format:check
112 changes: 112 additions & 0 deletions __tests__/authProviders.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import {
TokenAuthProvider,
FormAuthProvider,
AuthProviderFactory,
AuthProviderType
} from '../src/onegetjs/auth'
import { HttpClient } from '../src/onegetjs/httpClient'

describe('Auth Providers', () => {
const login = process.env.ONEC_USERNAME ?? 'test'
const password = process.env.ONEC_PASSWORD ?? 'test'

it('TokenAuthProvider should be instantiable', () => {
const provider = new TokenAuthProvider(login, password)
expect(provider).toBeDefined()
expect(typeof provider.authenticate).toBe('function')
})

it('FormAuthProvider should be instantiable', () => {
const provider = new FormAuthProvider(login, password)
expect(provider).toBeDefined()
expect(typeof provider.authenticate).toBe('function')
})

it('AuthProviderFactory should create TOKEN provider', () => {
const provider = AuthProviderFactory.create({
username: login,
password: password,
preferredProvider: AuthProviderType.TOKEN
})

expect(provider).toBeDefined()
expect(provider).toBeInstanceOf(TokenAuthProvider)
})

it('AuthProviderFactory should create FORM provider by default', () => {
const provider = AuthProviderFactory.create({
username: login,
password: password
})

expect(provider).toBeInstanceOf(FormAuthProvider)
})

it('AuthProviderFactory should respect FORM provider', () => {
const provider = AuthProviderFactory.create({
username: login,
password: password,
preferredProvider: AuthProviderType.FORM
})

expect(provider).toBeInstanceOf(FormAuthProvider)
})

// Тесты реальной аутентификации (требуют переменные окружения)
describe('Real Authentication', () => {
const hasCredentials =
login && password && login !== 'test' && password !== 'test'

it('TokenAuthProvider should attempt authentication', async () => {
if (!hasCredentials) {
console.log('Skipping TokenAuthProvider test - no credentials')
return
}

const provider = new TokenAuthProvider(login, password)
const httpClient = new HttpClient()
try {
await provider.authenticate(httpClient)
// Если дошли сюда - аутентификация прошла
expect(true).toBe(true)
} catch (error) {
// Ожидаем ошибку, но проверяем что это правильная ошибка аутентификации
expect(error).toBeDefined()
expect((error as Error).message.toLowerCase()).toContain(
'authentication'
)
Comment on lines +72 to +77
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Relax the TokenAuthProvider error message assertion.

TokenAuthProvider can throw errors like “Auth failed with status ...”, which won’t include “authentication”, so the assertion is brittle.

🧪 Suggested fix
-        expect((error as Error).message.toLowerCase()).toContain(
-          'authentication'
-        )
+        expect((error as Error).message.toLowerCase()).toMatch(/auth|login|token/)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} catch (error) {
// Ожидаем ошибку, но проверяем что это правильная ошибка аутентификации
expect(error).toBeDefined()
expect((error as Error).message.toLowerCase()).toContain(
'authentication'
)
} catch (error) {
// Ожидаем ошибку, но проверяем что это правильная ошибка аутентификации
expect(error).toBeDefined()
expect((error as Error).message.toLowerCase()).toMatch(/auth|login|token/)
}
🤖 Prompt for AI Agents
In `@__tests__/authProviders.test.ts` around lines 72 - 77, The test's error
assertion is too strict for TokenAuthProvider; update the catch block in the
authProviders.test.ts test to assert more flexibly—for example check that error
is defined and that (error as Error).message matches a case-insensitive
substring like "auth" or "failed" (e.g., use a regex /auth|failed/i) or simply
assert it's an instance of Error—so modify the expect((error as
Error).message.toLowerCase()).toContain('authentication') to a looser check that
will accept messages like "Auth failed with status ...".

}
}, 30000)

it('FormAuthProvider should attempt authentication', async () => {
const provider = new FormAuthProvider(login, password)
const httpClient = new HttpClient()
await provider.authenticate(httpClient)
// Если дошли сюда - аутентификация прошла
expect(true).toBe(true)
}, 30000)
Comment on lines +81 to +87
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Skip or handle FormAuthProvider auth when credentials are missing.

This test runs even when hasCredentials is false (defaults to 'test'), so it will fail in CI without real credentials.

🧪 Suggested fix
-    it('FormAuthProvider should attempt authentication', async () => {
-      const provider = new FormAuthProvider(login, password)
-      const httpClient = new HttpClient()
-      await provider.authenticate(httpClient)
-      // Если дошли сюда - аутентификация прошла
-      expect(true).toBe(true)
-    }, 30000)
+    it('FormAuthProvider should attempt authentication', async () => {
+      if (!hasCredentials) {
+        console.log('Skipping FormAuthProvider test - no credentials')
+        return
+      }
+      const provider = new FormAuthProvider(login, password)
+      const httpClient = new HttpClient()
+      await provider.authenticate(httpClient)
+      // Если дошли сюда - аутентификация прошла
+      expect(true).toBe(true)
+    }, 30000)
🤖 Prompt for AI Agents
In `@__tests__/authProviders.test.ts` around lines 81 - 87, The test invoking
FormAuthProvider.authenticate should not run when real credentials are absent;
update the test in authProviders.test.ts to guard on the hasCredentials flag (or
use test.skip) so it only executes when credentials are provided, or
alternatively supply mocked credentials/http behavior; specifically modify the
it block that creates FormAuthProvider(login, password) and HttpClient and calls
provider.authenticate(httpClient) to early-skip when hasCredentials is false (or
substitute a mocked HttpClient/credentials) to avoid CI failures.


it('AuthProviderFactory should create working provider', async () => {
if (!hasCredentials) {
console.log('Skipping AuthProviderFactory test - no credentials')
return
}

const provider = AuthProviderFactory.create({
username: login,
password: password
})

const httpClient = new HttpClient()
// Проверяем что провайдер может выполнять аутентификацию
try {
await provider.authenticate(httpClient)
const response = await httpClient.get('https://releases.1c.ru')
expect(response.status).toBe(200)
} catch (error) {
// Ожидаем ошибку из-за отсутствия аутентификации
expect(error).toBeDefined()
}
}, 30000)
})
})
26 changes: 23 additions & 3 deletions __tests__/downloader.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
import { Client } from '../src/onegetjs/downloader'
import { AuthProviderType } from '../src/onegetjs/auth'

describe('downloader.ts', () => {
const login = process.env.ONEC_USERNAME ?? ''
const password = process.env.ONEC_PASSWORD ?? ''
const client = new Client(login, password)

it('auth', async () => {
await client.auth()
it('auth with token provider', async () => {
const client = new Client(login, password, {
preferredProvider: AuthProviderType.TOKEN
})
try {
Comment on lines 5 to +12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Avoid constructor throw when env credentials are missing.

Client throws if login/password are empty; that happens before the try/catch, so these tests will fail in environments without secrets. Consider defaulting to non-empty placeholders or skipping when env vars are absent.

✅ Suggested fix (placeholders)
-  const login = process.env.ONEC_USERNAME ?? ''
-  const password = process.env.ONEC_PASSWORD ?? ''
+  const login = process.env.ONEC_USERNAME ?? 'test'
+  const password = process.env.ONEC_PASSWORD ?? 'test'
🤖 Prompt for AI Agents
In `@__tests__/downloader.test.ts` around lines 5 - 12, The test creates a Client
with login/password derived from process.env which can be empty and causes the
Client constructor to throw before the try/catch; modify the test to either
provide safe defaults or skip when credentials are missing: check the
login/password variables and if empty call test.skip for the "auth with token
provider" case, or set non-empty placeholder credentials before constructing new
Client(login, password, { preferredProvider: AuthProviderType.TOKEN }) so the
Client constructor never throws; reference the Client constructor, the
login/password variables and the test named "auth with token provider" when
applying the change.

await client.auth()
} catch (error) {
// Ожидаем ошибку из-за отсутствия реальных учетных данных
expect(error).toBeDefined()
}
})

it('auth with form provider', async () => {
const client = new Client(login, password, {
preferredProvider: AuthProviderType.FORM
})
try {
await client.auth()
} catch (error) {
// Ожидаем ошибку из-за отсутствия реальных учетных данных
expect(error).toBeDefined()
}
})
})
6 changes: 2 additions & 4 deletions __tests__/ongetjs.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { downloadRelease } from '../src/onegetjs'
import { config } from 'dotenv'

const TIMEOUT = 500000

describe('onegetjs', () => {
config()
// const client = new OneGet('/tmp/oneget')
//
// it('versionInfo', async () => {
Expand Down Expand Up @@ -36,9 +34,9 @@ describe('onegetjs', () => {
{
project: 'Platform83',
version: '8.3.10.2580',
osName: 'win',
osName: 'deb',
architecture: 'x64',
type: 'full'
type: 'clientOrServer'
},
'/tmp/oneget/test',
true
Expand Down
25 changes: 25 additions & 0 deletions __tests__/parse.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { versions } from '../src/onegetjs/parse'

describe('parse.ts', () => {
it('should parse versions from HTML', () => {
const html = `
<table>
<tr>
<td class="versionColumn">
<a href="/version/8.3.25.1286">8.3.25.1286</a>
</td>
</tr>
<tr>
<td class="versionColumn">
<a href="/version/8.3.24.1500">8.3.24.1500</a>
</td>
</tr>
</table>
`

const result = versions(html)
expect(result).toHaveLength(2)
expect(result[0].name).toBe('8.3.25.1286')
expect(result[1].name).toBe('8.3.24.1500')
})
})
Loading
Loading