mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 21:15:32 +09:00
chore(repo): remove dead code and useless tests (#3375)
This commit is contained in:
1 parent
7e177a1c90
commit
1cd62eb661
1391 files changed
+783
-120415
No files matched your search
@@ -52,8 +52,6 @@ export interface AudioFrame {
|
||||
|
||||
export declare const loadError: Error | null;
|
||||
|
||||
export declare function __setBindingForTests(binding: unknown): void;
|
||||
|
||||
export declare function pidFromWindowId(windowId: number): number;
|
||||
|
||||
export declare function listAudibleApplications(): Promise<Array<MacApplicationDescriptor>>;
|
||||
|
||||
@@ -98,11 +98,6 @@ function getBackendAvailability() {
|
||||
return binding.getBackendAvailability();
|
||||
}
|
||||
|
||||
function __setBindingForTests(nextBinding) {
|
||||
binding = nextBinding;
|
||||
loadError = null;
|
||||
}
|
||||
|
||||
class ProcessLoopback extends EventEmitter {
|
||||
constructor(pid, options = {}) {
|
||||
super();
|
||||
@@ -204,5 +199,4 @@ module.exports = {
|
||||
getBackendInfo,
|
||||
pidFromWindowId,
|
||||
loadError,
|
||||
__setBindingForTests,
|
||||
};
|
||||
@@ -1,132 +0,0 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {createRequire} from 'node:module';
|
||||
import {afterEach, describe, expect, test} from 'vitest';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const macAppAudio = require('./index.js');
|
||||
|
||||
function makeFakeBinding() {
|
||||
const calls = [];
|
||||
const natives = [];
|
||||
class FakeNative {
|
||||
constructor() {
|
||||
this.frameCallback = undefined;
|
||||
this.lifecycleCallback = undefined;
|
||||
this.stopCount = 0;
|
||||
natives.push(this);
|
||||
}
|
||||
|
||||
setFrameCallback(callback) {
|
||||
this.frameCallback = callback;
|
||||
}
|
||||
|
||||
setLifecycleCallback(callback) {
|
||||
this.lifecycleCallback = callback;
|
||||
}
|
||||
|
||||
async start(pid, excludeSelf, includeProcessTree, backend, captureScope) {
|
||||
calls.push({pid, excludeSelf, includeProcessTree, backend, captureScope});
|
||||
}
|
||||
|
||||
async stop() {
|
||||
this.stopCount += 1;
|
||||
}
|
||||
}
|
||||
return {
|
||||
binding: {
|
||||
ProcessLoopback: FakeNative,
|
||||
listAudibleApplications: async () => [],
|
||||
getBackendAvailability: async () => ({}),
|
||||
pidFromWindowId: () => 0,
|
||||
},
|
||||
calls,
|
||||
natives,
|
||||
};
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
macAppAudio.__setBindingForTests(null);
|
||||
});
|
||||
|
||||
describe('mac-app-audio loader wrapper', () => {
|
||||
test('forces excludeSelf=true and preserves includeProcessTree=false', async () => {
|
||||
const {binding, calls} = makeFakeBinding();
|
||||
macAppAudio.__setBindingForTests(binding);
|
||||
const loopback = new macAppAudio.ProcessLoopback(1234, {
|
||||
excludeSelf: false,
|
||||
includeProcessTree: false,
|
||||
});
|
||||
loopback.on('error', () => {});
|
||||
await loopback.start();
|
||||
expect(calls).toEqual([
|
||||
{pid: 1234, excludeSelf: true, includeProcessTree: false, backend: 'auto', captureScope: 'process'},
|
||||
]);
|
||||
});
|
||||
test('forwards explicit backend preference to native binding', async () => {
|
||||
const {binding, calls} = makeFakeBinding();
|
||||
macAppAudio.__setBindingForTests(binding);
|
||||
const loopback = new macAppAudio.ProcessLoopback(1234, {
|
||||
backend: 'coreaudio',
|
||||
});
|
||||
loopback.on('error', () => {});
|
||||
await loopback.start();
|
||||
expect(calls).toEqual([
|
||||
{pid: 1234, excludeSelf: true, includeProcessTree: true, backend: 'coreaudio', captureScope: 'process'},
|
||||
]);
|
||||
});
|
||||
test('forwards explicit capture scope to native binding', async () => {
|
||||
const {binding, calls} = makeFakeBinding();
|
||||
macAppAudio.__setBindingForTests(binding);
|
||||
const loopback = new macAppAudio.ProcessLoopback(1234, {
|
||||
captureScope: 'system',
|
||||
backend: 'coreaudio',
|
||||
});
|
||||
loopback.on('error', () => {});
|
||||
await loopback.start();
|
||||
expect(calls).toEqual([
|
||||
{pid: 1234, excludeSelf: true, includeProcessTree: true, backend: 'coreaudio', captureScope: 'system'},
|
||||
]);
|
||||
});
|
||||
test('forwards ScreenCaptureKit system capture requests to native binding', async () => {
|
||||
const {binding, calls} = makeFakeBinding();
|
||||
macAppAudio.__setBindingForTests(binding);
|
||||
const loopback = new macAppAudio.ProcessLoopback(1234, {
|
||||
captureScope: 'system',
|
||||
backend: 'sck',
|
||||
});
|
||||
loopback.on('error', () => {});
|
||||
await loopback.start();
|
||||
expect(calls).toEqual([
|
||||
{pid: 1234, excludeSelf: true, includeProcessTree: true, backend: 'sck', captureScope: 'system'},
|
||||
]);
|
||||
});
|
||||
test('copies native frame samples before emitting', () => {
|
||||
const {binding, natives} = makeFakeBinding();
|
||||
macAppAudio.__setBindingForTests(binding);
|
||||
const loopback = new macAppAudio.ProcessLoopback(1234);
|
||||
const frames = [];
|
||||
loopback.on('frame', (frame) => frames.push(frame));
|
||||
const nativeSamples = new Float32Array([0.1, 0.2, 0.3, 0.4]);
|
||||
natives[0].frameCallback(nativeSamples);
|
||||
nativeSamples.fill(9);
|
||||
expect(frames).toHaveLength(1);
|
||||
expect(Array.from(frames[0].samples)).toEqual(Array.from(new Float32Array([0.1, 0.2, 0.3, 0.4])));
|
||||
expect(frames[0].channels).toBe(2);
|
||||
expect(frames[0].sampleRate).toBe(48000);
|
||||
});
|
||||
test('emits closed once when native lifecycle closes and stop is called later', async () => {
|
||||
const {binding, natives} = makeFakeBinding();
|
||||
macAppAudio.__setBindingForTests(binding);
|
||||
const loopback = new macAppAudio.ProcessLoopback(1234);
|
||||
let closed = 0;
|
||||
loopback.on('closed', () => {
|
||||
closed += 1;
|
||||
});
|
||||
natives[0].lifecycleCallback('closed', '');
|
||||
await Promise.resolve();
|
||||
await loopback.stop();
|
||||
expect(closed).toBe(1);
|
||||
expect(natives[0].stopCount).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -22,15 +22,11 @@
|
||||
],
|
||||
"scripts": {
|
||||
"build": "cargo run --locked --quiet --manifest-path ../../../tools/ci/Cargo.toml -- build-desktop-native-addon",
|
||||
"test": "pnpm test:cargo && ../../../node_modules/.bin/vitest run",
|
||||
"test:cargo": "cargo test --manifest-path Cargo.toml"
|
||||
"test": "cargo test --manifest-path Cargo.toml"
|
||||
},
|
||||
"binary": {
|
||||
"napi_versions": [
|
||||
8
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"vitest": "catalog:"
|
||||
}
|
||||
}
|
||||
@@ -96,101 +96,3 @@ pub fn classify_support(detected: Option<(i64, i64, i64)>) -> SupportClassificat
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn meets_floor_exact_match() {
|
||||
assert!(meets_floor((12, 3, 0), SCK_MIN_MACOS));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn meets_floor_higher_major() {
|
||||
assert!(meets_floor((14, 0, 0), SCK_MIN_MACOS));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn meets_floor_higher_minor() {
|
||||
assert!(meets_floor((12, 4, 0), SCK_MIN_MACOS));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_below_floor_minor() {
|
||||
assert!(!meets_floor((12, 2, 9), SCK_MIN_MACOS));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_below_floor_major() {
|
||||
assert!(!meets_floor((11, 7, 10), SCK_MIN_MACOS));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_macos_10_15_for_sck() {
|
||||
assert!(!meets_floor((10, 15, 7), SCK_MIN_MACOS));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn coreaudio_floor_14_2() {
|
||||
assert!(meets_floor((14, 2, 0), COREAUDIO_TAP_MIN_MACOS));
|
||||
assert!(!meets_floor((14, 1, 9), COREAUDIO_TAP_MIN_MACOS));
|
||||
assert!(meets_floor((15, 0, 0), COREAUDIO_TAP_MIN_MACOS));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_version_trims_zero_patch() {
|
||||
assert_eq!("12.3", format_version((12, 3, 0)));
|
||||
assert_eq!("14.2.1", format_version((14, 2, 1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn classify_unknown_version_is_unsupported() {
|
||||
let c = classify_support(None);
|
||||
assert!(!c.supported);
|
||||
assert!(!c.sck_available);
|
||||
assert!(!c.coreaudio_available);
|
||||
assert!(c.reason.contains("could not detect"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn classify_macos_10_15_is_unsupported_and_mentions_min_version() {
|
||||
let c = classify_support(Some((10, 15, 7)));
|
||||
assert!(!c.supported);
|
||||
assert!(!c.sck_available);
|
||||
assert!(!c.coreaudio_available);
|
||||
assert!(c.reason.contains("macOS 12.3+"), "reason: {}", c.reason);
|
||||
assert!(c.reason.contains("macOS 10.15.7"), "reason: {}", c.reason);
|
||||
assert!(c.reason.contains("ScreenCaptureKit"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn classify_macos_12_3_is_sck_only() {
|
||||
let c = classify_support(Some((12, 3, 0)));
|
||||
assert!(c.supported);
|
||||
assert!(c.sck_available);
|
||||
assert!(!c.coreaudio_available);
|
||||
assert!(c.reason.contains("ScreenCaptureKit per-app capture"));
|
||||
assert!(
|
||||
c.reason
|
||||
.contains("CoreAudio process tap requires macOS 14.2+")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn classify_macos_14_2_has_both_backends() {
|
||||
let c = classify_support(Some((14, 2, 0)));
|
||||
assert!(c.supported);
|
||||
assert!(c.sck_available);
|
||||
assert!(c.coreaudio_available);
|
||||
assert!(c.reason.contains("CoreAudio process tap"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn classify_macos_15_is_supported() {
|
||||
let c = classify_support(Some((15, 0, 0)));
|
||||
assert!(c.supported);
|
||||
assert!(c.sck_available);
|
||||
assert!(c.coreaudio_available);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user